Total Complexity | 10 |
Total Lines | 256 |
Duplicated Lines | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
19 | final class DB2SchemaManagerTest extends TestCase |
||
20 | { |
||
21 | /** @var Connection|PHPUnit_Framework_MockObject_MockObject */ |
||
22 | private $conn; |
||
23 | |||
24 | /** @var DB2SchemaManager */ |
||
25 | private $manager; |
||
26 | |||
27 | protected function setUp() |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * @see https://github.com/doctrine/dbal/issues/2701 |
||
42 | * |
||
43 | * @return void |
||
44 | * |
||
45 | * @group DBAL-2701 |
||
46 | */ |
||
47 | public function testListTableNamesFiltersAssetNamesCorrectly() |
||
48 | { |
||
49 | $this->conn->getConfiguration()->setFilterSchemaAssetsExpression('/^(?!T_)/'); |
||
1 ignored issue
–
show
|
|||
50 | $this->conn->expects($this->once())->method('fetchAll')->will($this->returnValue([ |
||
51 | ['name' => 'FOO'], |
||
52 | ['name' => 'T_FOO'], |
||
53 | ['name' => 'BAR'], |
||
54 | ['name' => 'T_BAR'], |
||
55 | ])); |
||
56 | |||
57 | self::assertSame( |
||
58 | [ |
||
59 | 'FOO', |
||
60 | 'BAR', |
||
61 | ], |
||
62 | $this->manager->listTableNames() |
||
63 | ); |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * @return void |
||
68 | * |
||
69 | * @group DBAL-3692 |
||
70 | */ |
||
71 | public function testListAllTableNamesFiltersAssetNamesCorrectly() |
||
72 | { |
||
73 | $this->conn->getConfiguration()->setFilterSchemaAssetsExpression('/^(?!T_)/'); |
||
1 ignored issue
–
show
|
|||
74 | $this->conn->expects($this->once())->method('fetchAll')->will($this->returnValue([ |
||
75 | ['name' => 'FOO'], |
||
76 | ['name' => 'T_FOO'], |
||
77 | ['name' => 'BAR'], |
||
78 | ['name' => 'T_BAR'], |
||
79 | ])); |
||
80 | |||
81 | self::assertSame( |
||
82 | [ |
||
83 | 'FOO', |
||
84 | 'T_FOO', |
||
85 | 'BAR', |
||
86 | 'T_BAR', |
||
87 | ], |
||
88 | $this->manager->listAllTableNames() |
||
89 | ); |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * @return void |
||
94 | * |
||
95 | * @group DBAL-3692 |
||
96 | */ |
||
97 | public function testTablesExistWithoutFilteredParameter() |
||
98 | { |
||
99 | $this->conn->getConfiguration()->setFilterSchemaAssetsExpression('/^(?!T_)/'); |
||
1 ignored issue
–
show
|
|||
100 | $this->conn->expects($this->once())->method('fetchAll')->will($this->returnValue([ |
||
101 | ['name' => 'FOO'], |
||
102 | ['name' => 'T_FOO'], |
||
103 | ])); |
||
104 | |||
105 | self::assertEquals(false, $this->manager->tablesExist('T_FOO')); |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * @return void |
||
110 | * |
||
111 | * @group DBAL-3692 |
||
112 | */ |
||
113 | public function testTablesExistWhithFilteredTrueParameter() |
||
114 | { |
||
115 | $this->conn->getConfiguration()->setFilterSchemaAssetsExpression('/^(?!T_)/'); |
||
1 ignored issue
–
show
|
|||
116 | $this->conn->expects($this->once())->method('fetchAll')->will($this->returnValue([ |
||
117 | ['name' => 'FOO'], |
||
118 | ['name' => 'T_FOO'], |
||
119 | ])); |
||
120 | |||
121 | self::assertEquals(false, $this->manager->tablesExist('T_FOO', true)); |
||
122 | } |
||
123 | |||
124 | /** |
||
125 | * @return void |
||
126 | * |
||
127 | * @group DBAL-3692 |
||
128 | */ |
||
129 | public function testTablesExistWhithFilteredFalseParameter() |
||
130 | { |
||
131 | $this->conn->getConfiguration()->setFilterSchemaAssetsExpression('/^(?!T_)/'); |
||
1 ignored issue
–
show
|
|||
132 | $this->conn->expects($this->once())->method('fetchAll')->will($this->returnValue([ |
||
133 | ['name' => 'FOO'], |
||
134 | ['name' => 'T_FOO'], |
||
135 | ])); |
||
136 | |||
137 | self::assertEquals(true, $this->manager->tablesExist('T_FOO', false)); |
||
138 | } |
||
139 | |||
140 | /** |
||
141 | * @return void |
||
142 | * |
||
143 | * @group DBAL-2701 |
||
144 | */ |
||
145 | public function testAssetFilteringSetsACallable() |
||
146 | { |
||
147 | $filterExpression = '/^(?!T_)/'; |
||
148 | $this->conn->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); |
||
1 ignored issue
–
show
|
|||
149 | $this->conn->expects($this->once())->method('fetchAll')->will($this->returnValue([ |
||
150 | ['name' => 'FOO'], |
||
151 | ['name' => 'T_FOO'], |
||
152 | ['name' => 'BAR'], |
||
153 | ['name' => 'T_BAR'], |
||
154 | ])); |
||
155 | |||
156 | self::assertSame( |
||
157 | [ |
||
158 | 'FOO', |
||
159 | 'BAR', |
||
160 | ], |
||
161 | $this->manager->listTableNames() |
||
162 | ); |
||
163 | |||
164 | $callable = $this->conn->getConfiguration()->getSchemaAssetsFilter(); |
||
165 | $this->assertInternalType('callable', $callable); |
||
166 | |||
167 | // BC check: Test that regexp expression is still preserved & accessible. |
||
168 | $this->assertEquals($filterExpression, $this->conn->getConfiguration()->getFilterSchemaAssetsExpression()); |
||
169 | } |
||
170 | |||
171 | /** |
||
172 | * @return void |
||
173 | */ |
||
174 | public function testListTableNamesFiltersAssetNamesCorrectlyWithCallable() |
||
175 | { |
||
176 | $accepted = ['T_FOO', 'T_BAR']; |
||
177 | $this->conn->getConfiguration()->setSchemaAssetsFilter(static function ($assetName) use ($accepted) { |
||
178 | return in_array($assetName, $accepted); |
||
179 | }); |
||
180 | $this->conn->expects($this->any())->method('quote'); |
||
181 | $this->conn->expects($this->once())->method('fetchAll')->will($this->returnValue([ |
||
182 | ['name' => 'FOO'], |
||
183 | ['name' => 'T_FOO'], |
||
184 | ['name' => 'BAR'], |
||
185 | ['name' => 'T_BAR'], |
||
186 | ])); |
||
187 | |||
188 | self::assertSame( |
||
189 | [ |
||
190 | 'T_FOO', |
||
191 | 'T_BAR', |
||
192 | ], |
||
193 | $this->manager->listTableNames() |
||
194 | ); |
||
195 | |||
196 | $this->assertNull($this->conn->getConfiguration()->getFilterSchemaAssetsExpression()); |
||
197 | } |
||
198 | |||
199 | /** |
||
200 | * @return void |
||
201 | */ |
||
202 | public function testSettingNullExpressionWillResetCallable() |
||
237 | } |
||
238 | |||
239 | /** |
||
240 | * @return void |
||
241 | */ |
||
242 | public function testSettingNullAsCallableClearsExpression() |
||
275 | } |
||
276 | } |
||
277 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.