-
-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/3.4.x' into 4.0.x
- Loading branch information
Showing
6 changed files
with
148 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: "Composer Lint" | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- "*.x" | ||
paths: | ||
- ".github/workflows/composer-lint.yml" | ||
- "composer.json" | ||
push: | ||
branches: | ||
- "*.x" | ||
paths: | ||
- ".github/workflows/composer-lint.yml" | ||
- "composer.json" | ||
|
||
jobs: | ||
composer-lint: | ||
name: "Composer Lint" | ||
uses: "doctrine/.github/.github/workflows/[email protected]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Bundle\MigrationsBundle\EventListener; | ||
|
||
use Doctrine\DBAL\Schema\AbstractAsset; | ||
use Doctrine\Migrations\Tools\Console\Command\DoctrineCommand; | ||
use Symfony\Component\Console\Event\ConsoleCommandEvent; | ||
|
||
/** | ||
* Acts as a schema filter that hides the migration metadata table except | ||
* when the execution context is that of command inside the migrations | ||
* namespace. | ||
*/ | ||
final class SchemaFilterListener | ||
{ | ||
/** @var string */ | ||
private $configurationTableName; | ||
Check failure on line 19 in src/EventListener/SchemaFilterListener.php GitHub Actions / Coding Standards / Coding Standards (PHP: 8.4)
|
||
|
||
public function __construct(string $configurationTableName) | ||
{ | ||
$this->configurationTableName = $configurationTableName; | ||
} | ||
|
||
/** @var bool */ | ||
private $enabled = true; | ||
Check failure on line 27 in src/EventListener/SchemaFilterListener.php GitHub Actions / Coding Standards / Coding Standards (PHP: 8.4)
|
||
|
||
/** @param AbstractAsset|string $asset */ | ||
public function __invoke($asset): bool | ||
Check failure on line 30 in src/EventListener/SchemaFilterListener.php GitHub Actions / Coding Standards / Coding Standards (PHP: 8.4)
|
||
{ | ||
if (! $this->enabled) { | ||
return true; | ||
} | ||
|
||
if ($asset instanceof AbstractAsset) { | ||
$asset = $asset->getName(); | ||
} | ||
|
||
return $asset !== $this->configurationTableName; | ||
} | ||
|
||
private function disable(): void | ||
{ | ||
$this->enabled = false; | ||
} | ||
|
||
public function onConsoleCommand(ConsoleCommandEvent $event): void | ||
{ | ||
$command = $event->getCommand(); | ||
|
||
if (! $command instanceof DoctrineCommand) { | ||
return; | ||
} | ||
|
||
$this->disable(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
tests/Collector/EventListener/SchemaFilterListenerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Bundle\MigrationsBundle\Tests\Collector\EventListener; | ||
|
||
use Doctrine\Bundle\MigrationsBundle\EventListener\SchemaFilterListener; | ||
use Doctrine\DBAL\Schema\Table; | ||
use Doctrine\Migrations\Tools\Console\Command\DoctrineCommand; | ||
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 | ||
{ | ||
$listener = new SchemaFilterListener('doctrine_migration_versions'); | ||
|
||
self::assertFalse($listener(new Table('doctrine_migration_versions'))); | ||
self::assertTrue($listener(new Table('some_other_table'))); | ||
} | ||
|
||
public function testItDisablesItselfWhenTheCurrentCommandIsAMigrationsCommand(): void | ||
{ | ||
$listener = new SchemaFilterListener('doctrine_migration_versions'); | ||
$migrationsCommand = new class extends DoctrineCommand { | ||
}; | ||
|
||
$listener->onConsoleCommand(new ConsoleCommandEvent( | ||
$migrationsCommand, | ||
new ArrayInput([]), | ||
new NullOutput() | ||
)); | ||
|
||
self::assertTrue($listener(new Table('doctrine_migration_versions'))); | ||
} | ||
} |