Completed
Pull Request — master (#265)
by Chris
05:34
created

testSchemaProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 16
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Bundle\MigrationsBundle\Tests\DependencyInjection;
6
7
use Doctrine\Bundle\MigrationsBundle\DependencyInjection\DoctrineMigrationsExtension;
8
use Doctrine\Migrations\Configuration\Configuration;
9
use Doctrine\Migrations\Provider\StubSchemaProvider;
10
use PHPUnit\Framework\TestCase;
11
use Symfony\Component\DependencyInjection\ContainerBuilder;
12
use Symfony\Component\DependencyInjection\Definition;
13
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
14
use Symfony\Component\DependencyInjection\Reference;
15
use function sys_get_temp_dir;
16
17
class DoctrineMigrationsExtensionTest extends TestCase
18
{
19
    public function testOrganizeMigrations() : void
20
    {
21
        $container = $this->getContainer();
22
        $extension = new DoctrineMigrationsExtension();
23
24
        $config = ['organize_migrations' => 'BY_YEAR'];
25
26
        $extension->load(['doctrine_migrations' => $config], $container);
27
28
        $this->assertEquals(
29
            Configuration::VERSIONS_ORGANIZATION_BY_YEAR,
30
            $container->getParameter('doctrine_migrations.organize_migrations')
31
        );
32
    }
33
34
    public function testSchemaProvider() : void
35
    {
36
        $container = $this->getContainer();
37
        $container->set('app.schema_provider', new Definition(StubSchemaProvider::class));
38
39
        $extension = new DoctrineMigrationsExtension();
40
41
        $config = ['schema_provider' => 'app.schema_provider'];
42
43
        $extension->load(['doctrine_migrations' => $config], $container);
44
45
        $diffCommand = $container->findDefinition('doctrine_migrations.diff_command');
46
47
        $this->assertEquals(
48
            new Reference('app.schema_provider'),
49
            $diffCommand->getArgument(0)
50
        );
51
    }
52
53
    private function getContainer() : ContainerBuilder
54
    {
55
        return new ContainerBuilder(new ParameterBag([
56
            'kernel.debug' => false,
57
            'kernel.bundles' => [],
58
            'kernel.cache_dir' => sys_get_temp_dir(),
59
            'kernel.environment' => 'test',
60
            'kernel.root_dir' => __DIR__ . '/../../', // src dir
61
        ]));
62
    }
63
}
64