Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/3.4.x' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
greg0ire committed Jan 27, 2025
2 parents a2a11fb + e858ce0 commit 8e53ae8
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 20 deletions.
12 changes: 9 additions & 3 deletions .doctrine-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions .symfony.bundle.yaml
Original file line number Diff line number Diff line change
@@ -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"
14 changes: 5 additions & 9 deletions src/EventListener/SchemaFilterListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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
{
Expand All @@ -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;
}
}
41 changes: 36 additions & 5 deletions tests/Collector/EventListener/SchemaFilterListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,28 @@
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;
use Symfony\Component\Console\Output\NullOutput;

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(
Expand All @@ -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<AbstractEntityManagerCommand> $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<string, array{class-string<AbstractEntityManagerCommand>}> */
public static function getCommands(): iterable
{
yield 'orm:validate-schema' => [ValidateSchemaCommand::class];
yield 'orm:schema-tool:update' => [UpdateCommand::class];
}
}

0 comments on commit 8e53ae8

Please sign in to comment.