-
-
Notifications
You must be signed in to change notification settings - Fork 214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for --complete #526
Draft
greg0ire
wants to merge
1
commit into
doctrine:3.4.x
Choose a base branch
from
greg0ire:complete-compat
base: 3.4.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Bundle\MigrationsBundle\EventListener; | ||
|
||
use Doctrine\DBAL\Schema\AbstractAsset; | ||
use Doctrine\Migrations\Metadata\Storage\TableMetadataStorageConfiguration; | ||
use Doctrine\Migrations\Tools\Console\Command\DoctrineCommand; | ||
use Symfony\Component\Console\Event\ConsoleCommandEvent; | ||
|
||
/** | ||
* Acts as a schema filter able that hides the migration metadata table except | ||
* when the execution context is that of command inside the migrations | ||
* namespace. | ||
*/ | ||
final class SchemaFilterListener | ||
{ | ||
/** @var bool */ | ||
private $enabled = true; | ||
|
||
/** @param AbstractAsset|string $asset */ | ||
public function __invoke($asset): bool | ||
{ | ||
if (! $this->enabled) { | ||
return true; | ||
} | ||
|
||
if ($asset instanceof AbstractAsset) { | ||
$asset = $asset->getName(); | ||
} | ||
|
||
return $asset !== (new TableMetadataStorageConfiguration())->getTableName(); | ||
} | ||
|
||
public function disable(): void | ||
{ | ||
$this->enabled = false; | ||
} | ||
|
||
public function onConsoleCommand(ConsoleCommandEvent $event): void | ||
{ | ||
$command = $event->getCommand(); | ||
|
||
if (! $command instanceof DoctrineCommand) { | ||
return; | ||
} | ||
|
||
$this->disable(); | ||
} | ||
} |
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
48 changes: 48 additions & 0 deletions
48
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,48 @@ | ||
<?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(); | ||
|
||
self::assertFalse($listener(new Table('doctrine_migration_versions'))); | ||
self::assertTrue($listener(new Table('some_other_table'))); | ||
} | ||
|
||
public function testItFiltersNothingWhenDisabled(): void | ||
{ | ||
$listener = new SchemaFilterListener(); | ||
$listener->disable(); | ||
|
||
self::assertTrue($listener(new Table('doctrine_migration_versions'))); | ||
self::assertTrue($listener(new Table('some_other_table'))); | ||
} | ||
|
||
public function testItDisablesItselfWhenTheCurrentCommandIsAMigrationsCommand(): void | ||
{ | ||
$listener = new SchemaFilterListener(); | ||
$migrationsCommand = new class extends DoctrineCommand { | ||
}; | ||
|
||
$listener->onConsoleCommand(new ConsoleCommandEvent( | ||
$migrationsCommand, | ||
new ArrayInput([]), | ||
new NullOutput() | ||
)); | ||
|
||
self::assertTrue($listener(new Table('doctrine_migration_versions'))); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ parameters: | |
phpVersion: 80200 | ||
paths: | ||
- DependencyInjection | ||
- EventListener | ||
- Tests | ||
|
||
excludePaths: | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the part I am not sure about, because I have been enable to test it. I've tried accessing the schema filter manager definition in order to inspect it after the compiler pass, like this:
That last line results in
Any ideas how to test this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doctrine.dbal.schema_asset_filter_manager
is defined as an abstract. The container builder removes unused and/or abstract definitions during its compilation causing the service to be hidden.An example fix, not per se the wanted fix, could be: