77use Doctrine \Bundle \MigrationsBundle \EventListener \SchemaFilterListener ;
88use Doctrine \DBAL \Schema \Table ;
99use 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 ;
1014use PHPUnit \Framework \TestCase ;
1115use Symfony \Component \Console \Event \ConsoleCommandEvent ;
1216use Symfony \Component \Console \Input \ArrayInput ;
1317use Symfony \Component \Console \Output \NullOutput ;
1418
1519class SchemaFilterListenerTest extends TestCase
1620{
17- public function testItFiltersOutMigrationMetadataTableByDefault (): void
21+ public function testItFiltersNothingByDefault (): void
1822 {
1923 $ 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 ' )));
2225 self ::assertTrue ($ listener (new Table ('some_other_table ' )));
2326 }
2427
25- public function testItDisablesItselfWhenTheCurrentCommandIsAMigrationsCommand (): void
28+ public function testItFiltersNothingWhenNotRunningSpecificCommands (): void
2629 {
2730 $ listener = new SchemaFilterListener ('doctrine_migration_versions ' );
28- $ migrationsCommand = new class extends DoctrineCommand {
31+ $ migrationsCommand = new class () extends DoctrineCommand {
2932 };
3033
3134 $ listener ->onConsoleCommand (new ConsoleCommandEvent (
@@ -35,5 +38,33 @@ public function testItDisablesItselfWhenTheCurrentCommandIsAMigrationsCommand():
3538 ));
3639
3740 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];
3869 }
3970}
0 commit comments