Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
1.73% covered (danger)
1.73%
3 / 173
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
get_schema_steps_test
1.73% covered (danger)
1.73%
3 / 173
66.67% covered (warning)
66.67%
2 / 3
11.54
0.00% covered (danger)
0.00%
0 / 1
 setUp
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 schema_provider
0.00% covered (danger)
0.00%
0 / 170
0.00% covered (danger)
0.00%
0 / 1
2
 test_get_schema_steps
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14class get_schema_steps_test extends phpbb_test_case
15{
16    protected $helper;
17
18    protected function setUp(): void
19    {
20        parent::setUp();
21
22        $this->helper = new \phpbb\db\migration\helper();
23    }
24
25    public static function schema_provider()
26    {
27        return array(
28            array(
29                array(
30                    'add_tables'    => array(
31                        'foo'    => array(
32                            'COLUMNS'            => array(
33                                'foobar'            => array('BOOL', 0),
34                                'foobar2'            => array('BOOL', 0),
35                            ),
36                            'PRIMARY_KEY'        => array('foobar'),
37                        ),
38                        'bar'    => array(
39                            'COLUMNS'            => array(
40                                'barfoo'            => array('BOOL', 0),
41                                'barfoor2'            => array('BOOL', 0),
42                            ),
43                            'PRIMARY_KEY'        => array('barfoo'),
44                        ),
45                    ),
46                    'drop_tables'    => array('table1', 'table2', 'table3'),
47                    'add_index'    => array(
48                        'table1'    => array(
49                            'index1'    => 'column1',
50                            'index2'    => 'column2',
51                        ),
52                        'table2'    => array(
53                            'index1'    => 'column1',
54                            'index2'    => 'column2',
55                        ),
56                    ),
57                    'add_columns'    => array(
58                        'table1'    => array(
59                            'column1'    => array('foo'),
60                            'column2'    => array('bar'),
61                        ),
62                    ),
63                    'change_columns'    => array(
64                        'table1'    => array(
65                            'column1'    => array('foo'),
66                            'column2'    => array('bar'),
67                        ),
68                    ),
69                    'drop_columns'    => array(
70                        'table1'    => array(
71                            'column1',
72                            'column2',
73                        ),
74                    ),
75                    'add_unique_index'    => array(
76                        'table1'    => array(
77                            'index1'    => 'column1',
78                            'index2'    => 'column2',
79                        ),
80                    ),
81                    'drop_keys'    => array(
82                        'table1'    => array(
83                            'column1',
84                            'column2',
85                        ),
86                    ),
87                    'add_primary_keys'    => array(
88                        'table1' => array('foo'),
89                        'table2' => array('bar'),
90                        'table3' => array('foobar'),
91                    ),
92                ),
93                array(
94                    array('dbtools.perform_schema_changes', array(array('drop_tables'    => array('table1')))),
95                    array('dbtools.perform_schema_changes', array(array('drop_tables'    => array('table2')))),
96                    array('dbtools.perform_schema_changes', array(array('drop_tables'    => array('table3')))),
97                    array('dbtools.perform_schema_changes', array(array('add_tables'    => array(
98                        'foo'    => array(
99                            'COLUMNS'            => array(
100                                'foobar'            => array('BOOL', 0),
101                                'foobar2'            => array('BOOL', 0),
102                            ),
103                            'PRIMARY_KEY'        => array('foobar'),
104                        ),
105                    )))),
106                    array('dbtools.perform_schema_changes', array(array('add_tables'    => array(
107                        'bar'    => array(
108                            'COLUMNS'            => array(
109                                'barfoo'            => array('BOOL', 0),
110                                'barfoor2'            => array('BOOL', 0),
111                            ),
112                            'PRIMARY_KEY'        => array('barfoo'),
113                        ),
114                    )))),
115                    array('dbtools.perform_schema_changes', array(array('change_columns'    => array(
116                        'table1'    => array(
117                            'column1'    => array('foo'),
118                        ),
119                    )))),
120                    array('dbtools.perform_schema_changes', array(array('change_columns'    => array(
121                        'table1'    => array(
122                            'column2'    => array('bar'),
123                        ),
124                    )))),
125                    array('dbtools.perform_schema_changes', array(array('add_columns'    => array(
126                        'table1'    => array(
127                            'column1'    => array('foo'),
128                        ),
129                    )))),
130                    array('dbtools.perform_schema_changes', array(array('add_columns'    => array(
131                        'table1'    => array(
132                            'column2'    => array('bar'),
133                        ),
134                    )))),
135                    array('dbtools.perform_schema_changes', array(array('drop_keys'    => array(
136                        'table1'    => array(
137                            0 => 'column1',
138                        ),
139                    )))),
140                    array('dbtools.perform_schema_changes', array(array('drop_keys'    => array(
141                        'table1'    => array(
142                            1 => 'column2',
143                        ),
144                    )))),
145                    array('dbtools.perform_schema_changes', array(array('drop_columns'    => array(
146                        'table1'    => array(
147                            0 => 'column1',
148                        ),
149                    )))),
150                    array('dbtools.perform_schema_changes', array(array('drop_columns'    => array(
151                        'table1'    => array(
152                            1 => 'column2',
153                        ),
154                    )))),
155                    array('dbtools.perform_schema_changes', array(array('add_primary_keys'    => array(
156                        'table1' => array('foo'),
157                    )))),
158                    array('dbtools.perform_schema_changes', array(array('add_primary_keys'    => array(
159                        'table2' => array('bar'),
160                    )))),
161                    array('dbtools.perform_schema_changes', array(array('add_primary_keys'    => array(
162                        'table3' => array('foobar'),
163                    )))),
164                    array('dbtools.perform_schema_changes', array(array('add_unique_index'    => array(
165                        'table1'    => array(
166                            'index1'    => 'column1',
167                        ),
168                    )))),
169                    array('dbtools.perform_schema_changes', array(array('add_unique_index'    => array(
170                        'table1'    => array(
171                            'index2'    => 'column2',
172                        ),
173                    )))),
174                    array('dbtools.perform_schema_changes', array(array('add_index'    => array(
175                        'table1'    => array(
176                            'index1'    => 'column1',
177                        ),
178                    )))),
179                    array('dbtools.perform_schema_changes', array(array('add_index'    => array(
180                        'table1'    => array(
181                            'index2'    => 'column2',
182                        ),
183                    )))),
184                    array('dbtools.perform_schema_changes', array(array('add_index'    => array(
185                        'table2'    => array(
186                            'index1'    => 'column1',
187                        ),
188                    )))),
189                    array('dbtools.perform_schema_changes', array(array('add_index'    => array(
190                        'table2'    => array(
191                            'index2'    => 'column2',
192                        ),
193                    )))),
194                ),
195            ),
196        );
197    }
198
199    /**
200     * @dataProvider schema_provider
201     */
202    public function test_get_schema_steps($schema_changes, $expected)
203    {
204        $this->assertEquals($expected, $this->helper->get_schema_steps($schema_changes));
205    }
206}