23
23
use Fresh \DoctrineEnumBundle \Exception \EnumType \EnumTypeIsRegisteredButClassDoesNotExistException ;
24
24
use Fresh \DoctrineEnumBundle \Tests \Fixtures \DBAL \Types \BasketballPositionType ;
25
25
use Fresh \DoctrineEnumBundle \Tests \Fixtures \DBAL \Types \TaskStatusType ;
26
+ use PHPUnit \Framework \Attributes \DataProvider ;
27
+ use PHPUnit \Framework \Attributes \Test ;
26
28
use PHPUnit \Framework \MockObject \MockObject ;
27
29
use PHPUnit \Framework \TestCase ;
28
30
use Symfony \Component \Console \Application ;
@@ -94,7 +96,8 @@ protected function tearDown(): void
94
96
);
95
97
}
96
98
97
- public function testExceptionInConstructor (): void
99
+ #[Test]
100
+ public function exceptionInConstructor (): void
98
101
{
99
102
$ this ->expectException (EnumTypeIsRegisteredButClassDoesNotExistException::class);
100
103
$ this ->expectExceptionMessage ('ENUM type "CustomType" is registered as "Fresh\DoctrineEnumBundle\Tests\Fixtures\DBAL\Types\CustomType", but that class does not exist ' );
@@ -110,7 +113,8 @@ public function testExceptionInConstructor(): void
110
113
$ this ->commandTester ->getDisplay ();
111
114
}
112
115
113
- public function testExceptionOnExecution (): void
116
+ #[Test]
117
+ public function exceptionOnExecution (): void
114
118
{
115
119
$ this ->em
116
120
->expects (self ::once ())
@@ -130,7 +134,8 @@ public function testExceptionOnExecution(): void
130
134
self ::assertStringContainsString ('test ' , $ output );
131
135
}
132
136
133
- public function testInvalidEnumTypeArgument (): void
137
+ #[Test]
138
+ public function invalidEnumTypeArgument (): void
134
139
{
135
140
$ result = $ this ->commandTester ->execute (
136
141
[
@@ -144,7 +149,8 @@ public function testInvalidEnumTypeArgument(): void
144
149
self ::assertStringContainsString ('Argument "enumType" is not a string. ' , $ output );
145
150
}
146
151
147
- public function testExceptionNotRegisteredEnumType (): void
152
+ #[Test]
153
+ public function exceptionNotRegisteredEnumType (): void
148
154
{
149
155
$ result = $ this ->commandTester ->execute (
150
156
[
@@ -158,27 +164,8 @@ public function testExceptionNotRegisteredEnumType(): void
158
164
self ::assertStringContainsString ('Argument "enumType" is not a registered ENUM type. ' , $ output );
159
165
}
160
166
161
- public function testMissingDatabasePlatformForConnection (): void
162
- {
163
- $ this ->connection
164
- ->expects (self ::once ())
165
- ->method ('getDatabasePlatform ' )
166
- ->willReturn (null )
167
- ;
168
-
169
- $ result = $ this ->commandTester ->execute (
170
- [
171
- 'command ' => $ this ->command ->getName (),
172
- 'enumType ' => 'TaskStatusType ' ,
173
- ]
174
- );
175
- self ::assertSame (3 , $ result );
176
-
177
- $ output = $ this ->commandTester ->getDisplay ();
178
- self ::assertStringContainsString ('Missing database platform for connection. ' , $ output );
179
- }
180
-
181
- public function testExecutionWithCaughtException (): void
167
+ #[Test]
168
+ public function executionWithCaughtException (): void
182
169
{
183
170
$ this ->connection
184
171
->expects (self ::once ())
@@ -198,7 +185,8 @@ public function testExecutionWithCaughtException(): void
198
185
self ::assertStringContainsString ('test ' , $ output );
199
186
}
200
187
201
- public function testSuccessfulExecutionWithNoMetadata (): void
188
+ #[Test]
189
+ public function successfulExecutionWithNoMetadata (): void
202
190
{
203
191
$ this ->connection
204
192
->expects (self ::once ())
@@ -226,7 +214,9 @@ public function testSuccessfulExecutionWithNoMetadata(): void
226
214
self ::assertStringContainsString ('NO METADATA FOUND ' , $ output );
227
215
}
228
216
229
- public function testSuccessfulExecutionWithMetadata (): void
217
+ #[Test]
218
+ #[DataProvider('dataProviderForMetadataTest ' )]
219
+ public function successfulExecutionWithMetadata (?string $ schemaName , string $ sqlColumnComment ): void
230
220
{
231
221
$ this ->connection
232
222
->expects (self ::once ())
@@ -242,12 +232,15 @@ public function testSuccessfulExecutionWithMetadata(): void
242
232
;
243
233
244
234
$ metadata ->expects (self ::once ())->method ('getName ' )->willReturn ('Task ' );
235
+ $ metadata ->expects (self ::atLeast (1 ))->method ('getSchemaName ' )->willReturn ($ schemaName );
245
236
$ metadata ->expects (self ::once ())->method ('getTableName ' )->willReturn ('tasks ' );
246
237
$ metadata ->expects (self ::once ())->method ('getFieldNames ' )->willReturn (['status ' ]);
247
238
$ metadata ->expects (self ::once ())->method ('getTypeOfField ' )->with ('status ' )->willReturn ('TaskStatusType ' );
248
- $ metadata ->expects (self ::once ())->method ('getFieldMapping ' )->with ('status ' )->willReturn (FieldMapping::fromMappingArray (['type ' => 'string ' , 'columnName ' => 'task_column_name ' , 'fieldName ' => 'test ' ]));
239
+ $ metadata ->expects (self ::once ())->method ('getFieldMapping ' )->with ('status ' )->willReturn (
240
+ FieldMapping::fromMappingArray (['type ' => 'string ' , 'columnName ' => 'task_column_name ' , 'fieldName ' => 'test ' ])
241
+ );
249
242
250
- $ this ->platform ->expects (self ::once ())->method ('getCommentOnColumnSQL ' )->with (' tasks ' , 'task_column_name ' , null )->willReturn ('test SQL ' );
243
+ $ this ->platform ->expects (self ::once ())->method ('getCommentOnColumnSQL ' )->with ($ sqlColumnComment , 'task_column_name ' , ' NULL ' )->willReturn ('test SQL ' );
251
244
252
245
$ this ->connection ->expects (self ::once ())->method ('executeQuery ' )->with ('test SQL ' );
253
246
@@ -266,4 +259,28 @@ public function testSuccessfulExecutionWithMetadata(): void
266
259
self ::assertStringContainsString ('TOTAL: 1 ' , $ output );
267
260
self ::assertStringContainsString ('DONE ' , $ output );
268
261
}
262
+
263
+ public static function dataProviderForMetadataTest (): iterable
264
+ {
265
+ yield 'no schema ' => [
266
+ 'schemaName ' => null ,
267
+ 'sqlColumnComment ' => 'tasks ' ,
268
+ ];
269
+ yield 'public schema ' => [
270
+ 'schemaName ' => 'public ' ,
271
+ 'sqlColumnComment ' => 'public.tasks ' ,
272
+ ];
273
+ yield 'custom schema ' => [
274
+ 'schemaName ' => 'custom ' ,
275
+ 'sqlColumnComment ' => 'custom.tasks ' ,
276
+ ];
277
+ }
278
+
279
+ #[Test]
280
+ public function autocomplete (): void
281
+ {
282
+ $ enumTypes = $ this ->command ->getEnumTypesForAutocompletion ()();
283
+
284
+ self ::assertSame (['BasketballPositionType ' , 'TaskStatusType ' ], $ enumTypes );
285
+ }
269
286
}
0 commit comments