diff --git a/.doctrine-project.json b/.doctrine-project.json index 3a2505f..66e7b37 100644 --- a/.doctrine-project.json +++ b/.doctrine-project.json @@ -4,16 +4,22 @@ "slug": "doctrine-migrations-bundle", "versions": [ { - "name": "3.4", - "branchName": "3.4.x", + "name": "4.0", + "branchName": "4.0.x", "slug": "latest", "upcoming": true }, + { + "name": "3.4", + "branchName": "3.4.x", + "slug": "3.4", + "current": true + }, { "name": "3.3", "branchName": "3.3.x", "slug": "3.3", - "current": true + "maintained": false }, { "name": "3.2", diff --git a/.symfony.bundle.yaml b/.symfony.bundle.yaml index 86ee4d1..72b9c53 100644 --- a/.symfony.bundle.yaml +++ b/.symfony.bundle.yaml @@ -1,4 +1,4 @@ -branches: ["2.2.x", "3.0.x", "3.1.x", "3.2.x", "3.3.x", "3.4.x"] -maintained_branches: ["2.2.x", "3.3.x", "3.4.x"] -doc_dir: {"2.2.x": "Resources/doc/", "3.3.x": "Resources/doc/", "3.4.x": "docs/"} +branches: ["3.0.x", "3.1.x", "3.2.x", "3.3.x", "3.4.x", "4.0.x"] +maintained_branches: ["3.4.x", "4.0.x"] +doc_dir: "docs/" dev_branch: "3.4.x" diff --git a/src/EventListener/SchemaFilterListener.php b/src/EventListener/SchemaFilterListener.php index 283e33b..25ff838 100644 --- a/src/EventListener/SchemaFilterListener.php +++ b/src/EventListener/SchemaFilterListener.php @@ -5,7 +5,8 @@ namespace Doctrine\Bundle\MigrationsBundle\EventListener; use Doctrine\DBAL\Schema\AbstractAsset; -use Doctrine\Migrations\Tools\Console\Command\DoctrineCommand; +use Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand; +use Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand; use Symfony\Component\Console\Event\ConsoleCommandEvent; /** @@ -19,7 +20,7 @@ public function __construct(private string $configurationTableName) { } - private bool $enabled = true; + private bool $enabled = false; public function __invoke(AbstractAsset|string $asset): bool { @@ -34,19 +35,14 @@ public function __invoke(AbstractAsset|string $asset): bool return $asset !== $this->configurationTableName; } - private function disable(): void - { - $this->enabled = false; - } - public function onConsoleCommand(ConsoleCommandEvent $event): void { $command = $event->getCommand(); - if (! $command instanceof DoctrineCommand) { + if (! $command instanceof ValidateSchemaCommand && ! $command instanceof UpdateCommand) { return; } - $this->disable(); + $this->enabled = true; } } diff --git a/tests/Collector/EventListener/SchemaFilterListenerTest.php b/tests/Collector/EventListener/SchemaFilterListenerTest.php index 87cb559..c57937b 100644 --- a/tests/Collector/EventListener/SchemaFilterListenerTest.php +++ b/tests/Collector/EventListener/SchemaFilterListenerTest.php @@ -7,6 +7,10 @@ use Doctrine\Bundle\MigrationsBundle\EventListener\SchemaFilterListener; use Doctrine\DBAL\Schema\Table; use Doctrine\Migrations\Tools\Console\Command\DoctrineCommand; +use Doctrine\ORM\Tools\Console\Command\AbstractEntityManagerCommand; +use Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand; +use Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand; +use Doctrine\ORM\Tools\Console\EntityManagerProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Event\ConsoleCommandEvent; use Symfony\Component\Console\Input\ArrayInput; @@ -14,18 +18,17 @@ class SchemaFilterListenerTest extends TestCase { - public function testItFiltersOutMigrationMetadataTableByDefault(): void + public function testItFiltersNothingByDefault(): void { $listener = new SchemaFilterListener('doctrine_migration_versions'); - - self::assertFalse($listener(new Table('doctrine_migration_versions'))); + self::assertTrue($listener(new Table('doctrine_migration_versions'))); self::assertTrue($listener(new Table('some_other_table'))); } - public function testItDisablesItselfWhenTheCurrentCommandIsAMigrationsCommand(): void + public function testItFiltersNothingWhenNotRunningSpecificCommands(): void { $listener = new SchemaFilterListener('doctrine_migration_versions'); - $migrationsCommand = new class extends DoctrineCommand { + $migrationsCommand = new class () extends DoctrineCommand { }; $listener->onConsoleCommand(new ConsoleCommandEvent( @@ -35,5 +38,33 @@ public function testItDisablesItselfWhenTheCurrentCommandIsAMigrationsCommand(): )); self::assertTrue($listener(new Table('doctrine_migration_versions'))); + self::assertTrue($listener(new Table('some_other_table'))); + } + + /** + * @param class-string $command + * + * @dataProvider getCommands + */ + public function testItFiltersOutMigrationMetadataTableWhenRunningSpecificCommands(string $command): void + { + $listener = new SchemaFilterListener('doctrine_migration_versions'); + $ormCommand = new $command(self::createStub(EntityManagerProvider::class)); + + $listener->onConsoleCommand(new ConsoleCommandEvent( + $ormCommand, + new ArrayInput([]), + new NullOutput(), + )); + + self::assertFalse($listener(new Table('doctrine_migration_versions'))); + self::assertTrue($listener(new Table('some_other_table'))); + } + + /** @return iterable}> */ + public static function getCommands(): iterable + { + yield 'orm:validate-schema' => [ValidateSchemaCommand::class]; + yield 'orm:schema-tool:update' => [UpdateCommand::class]; } }