HideMigrationStorageTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 22
c 1
b 0
f 0
dl 0
loc 48
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testItFiltersNothingByDefault() 0 5 1
A hp$0 ➔ testItFiltersOutMigrationMetadataTableWhenRunningSpecificCommands() 0 13 1
A hp$0 ➔ testItFiltersNothingWhenNotRunningSpecificCommands() 0 13 1
A hp$0 ➔ providerItFiltersOutMigrationMetadataTableWhenRunningSpecificCommands() 0 4 1
testItFiltersNothingWhenNotRunningSpecificCommands() 0 13 ?
testItFiltersOutMigrationMetadataTableWhenRunningSpecificCommands() 0 13 ?
providerItFiltersOutMigrationMetadataTableWhenRunningSpecificCommands() 0 4 ?
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));
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCase::createStub() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

51
        $ormCommand = new $command(self::/** @scrutinizer ignore-call */ createStub(EntityManagerProvider::class));
Loading history...
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