1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace EcodevTests\Felix\DBAL\EventListener; |
6
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Schema\Table; |
8
|
|
|
use Doctrine\Migrations\Tools\Console\Command\DoctrineCommand; |
9
|
|
|
use Doctrine\ORM\Tools\Console\Command\AbstractEntityManagerCommand; |
10
|
|
|
use Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand; |
11
|
|
|
use Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand; |
12
|
|
|
use Doctrine\ORM\Tools\Console\EntityManagerProvider; |
13
|
|
|
use Ecodev\Felix\DBAL\EventListener\HideMigrationStorage; |
14
|
|
|
use PHPUnit\Framework\TestCase; |
15
|
|
|
use Symfony\Component\Console\Event\ConsoleCommandEvent; |
16
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
17
|
|
|
use Symfony\Component\Console\Output\NullOutput; |
18
|
|
|
|
19
|
|
|
class HideMigrationStorageTest extends TestCase |
20
|
|
|
{ |
21
|
|
|
public function testItFiltersNothingByDefault(): void |
22
|
|
|
{ |
23
|
|
|
$service = new HideMigrationStorage('doctrine_migration_versions'); |
24
|
|
|
self::assertTrue($service(new Table('doctrine_migration_versions'))); |
25
|
|
|
self::assertTrue($service(new Table('some_other_table'))); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testItFiltersNothingWhenNotRunningSpecificCommands(): void |
29
|
|
|
{ |
30
|
|
|
$service = new HideMigrationStorage('doctrine_migration_versions'); |
31
|
|
|
$migrationsCommand = new class() extends DoctrineCommand {}; |
32
|
|
|
|
33
|
|
|
$service->dispatch(new ConsoleCommandEvent( |
34
|
|
|
$migrationsCommand, |
35
|
|
|
new ArrayInput([]), |
36
|
|
|
new NullOutput(), |
37
|
|
|
)); |
38
|
|
|
|
39
|
|
|
self::assertTrue($service(new Table('doctrine_migration_versions'))); |
40
|
|
|
self::assertTrue($service(new Table('some_other_table'))); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param class-string<AbstractEntityManagerCommand> $command |
45
|
|
|
* |
46
|
|
|
* @dataProvider providerItFiltersOutMigrationMetadataTableWhenRunningSpecificCommands |
47
|
|
|
*/ |
48
|
|
|
public function testItFiltersOutMigrationMetadataTableWhenRunningSpecificCommands(string $command): void |
49
|
|
|
{ |
50
|
|
|
$service = new HideMigrationStorage('doctrine_migration_versions'); |
51
|
|
|
$ormCommand = new $command(self::createStub(EntityManagerProvider::class)); |
|
|
|
|
52
|
|
|
|
53
|
|
|
$service->dispatch(new ConsoleCommandEvent( |
54
|
|
|
$ormCommand, |
55
|
|
|
new ArrayInput([]), |
56
|
|
|
new NullOutput(), |
57
|
|
|
)); |
58
|
|
|
|
59
|
|
|
self::assertFalse($service(new Table('doctrine_migration_versions'))); |
60
|
|
|
self::assertTrue($service(new Table('some_other_table'))); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public static function providerItFiltersOutMigrationMetadataTableWhenRunningSpecificCommands(): iterable |
64
|
|
|
{ |
65
|
|
|
yield 'orm:validate-schema' => [ValidateSchemaCommand::class]; |
66
|
|
|
yield 'orm:schema-tool:update' => [UpdateCommand::class]; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|