7
7
use Doctrine \Bundle \MigrationsBundle \EventListener \SchemaFilterListener ;
8
8
use Doctrine \DBAL \Schema \Table ;
9
9
use Doctrine \Migrations \Tools \Console \Command \DoctrineCommand ;
10
+ use Doctrine \ORM \Tools \Console \Command \AbstractEntityManagerCommand ;
11
+ use Doctrine \ORM \Tools \Console \Command \SchemaTool \UpdateCommand ;
12
+ use Doctrine \ORM \Tools \Console \Command \ValidateSchemaCommand ;
13
+ use Doctrine \ORM \Tools \Console \EntityManagerProvider ;
10
14
use PHPUnit \Framework \TestCase ;
11
15
use Symfony \Component \Console \Event \ConsoleCommandEvent ;
12
16
use Symfony \Component \Console \Input \ArrayInput ;
13
17
use Symfony \Component \Console \Output \NullOutput ;
14
18
15
19
class SchemaFilterListenerTest extends TestCase
16
20
{
17
- public function testItFiltersOutMigrationMetadataTableByDefault (): void
21
+ public function testItFiltersNothingByDefault (): void
18
22
{
19
23
$ listener = new SchemaFilterListener ('doctrine_migration_versions ' );
20
-
21
- self ::assertFalse ($ listener (new Table ('doctrine_migration_versions ' )));
24
+ self ::assertTrue ($ listener (new Table ('doctrine_migration_versions ' )));
22
25
self ::assertTrue ($ listener (new Table ('some_other_table ' )));
23
26
}
24
27
25
- public function testItDisablesItselfWhenTheCurrentCommandIsAMigrationsCommand (): void
28
+ public function testItFiltersNothingWhenNotRunningSpecificCommands (): void
26
29
{
27
30
$ listener = new SchemaFilterListener ('doctrine_migration_versions ' );
28
- $ migrationsCommand = new class extends DoctrineCommand {
31
+ $ migrationsCommand = new class () extends DoctrineCommand {
29
32
};
30
33
31
34
$ listener ->onConsoleCommand (new ConsoleCommandEvent (
@@ -35,5 +38,33 @@ public function testItDisablesItselfWhenTheCurrentCommandIsAMigrationsCommand():
35
38
));
36
39
37
40
self ::assertTrue ($ listener (new Table ('doctrine_migration_versions ' )));
41
+ self ::assertTrue ($ listener (new Table ('some_other_table ' )));
42
+ }
43
+
44
+ /**
45
+ * @param class-string<AbstractEntityManagerCommand> $command
46
+ *
47
+ * @dataProvider getCommands
48
+ */
49
+ public function testItFiltersOutMigrationMetadataTableWhenRunningSpecificCommands (string $ command ): void
50
+ {
51
+ $ listener = new SchemaFilterListener ('doctrine_migration_versions ' );
52
+ $ ormCommand = new $ command ($ this ->createStub (EntityManagerProvider::class));
53
+
54
+ $ listener ->onConsoleCommand (new ConsoleCommandEvent (
55
+ $ ormCommand ,
56
+ new ArrayInput ([]),
57
+ new NullOutput ()
58
+ ));
59
+
60
+ self ::assertFalse ($ listener (new Table ('doctrine_migration_versions ' )));
61
+ self ::assertTrue ($ listener (new Table ('some_other_table ' )));
62
+ }
63
+
64
+ /** @return iterable<string, array{class-string<AbstractEntityManagerCommand>}> */
65
+ public static function getCommands (): iterable
66
+ {
67
+ yield 'orm:validate-schema ' => [ValidateSchemaCommand::class];
68
+ yield 'orm:schema-tool:update ' => [UpdateCommand::class];
38
69
}
39
70
}
0 commit comments