SyncSchemaCommandTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
3
namespace Padam87\AttributeBundle\Tests\Command;
4
5
use Doctrine\Common\Persistence\ManagerRegistry;
6
use Doctrine\ORM\EntityManager;
7
use Doctrine\ORM\Tools\SchemaTool;
8
use Padam87\AttributeBundle\Command\SyncSchemaCommand;
9
use Symfony\Bundle\FrameworkBundle\Console\Application;
10
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
11
use Symfony\Component\Console\Tester\CommandTester;
12
13
class SyncSchemaCommandTest extends WebTestCase
14
{
15
    protected function setUp()
16
    {
17
        static::bootKernel();
18
19
        $container = static::$kernel->getContainer();
20
        /** @var ManagerRegistry $doctrine */
21
        $doctrine = $container->get('doctrine');
22
        /** @var EntityManager $em */
23
        $em = $doctrine->getManager();
24
        $metadata = $em->getMetadataFactory()->getAllMetadata();
25
        $schemaTool = new SchemaTool($em);
26
        $schemaTool->dropSchema($metadata);
27
        $schemaTool->createSchema($metadata);
28
    }
29
30
    /**
31
     * @test
32
     * @group functional
33
     */
34
    public function execute()
35
    {
36
        $application = new Application(static::$kernel);
37
        $application->add(new SyncSchemaCommand());
38
39
        $command = $application->find('eav:schema:sync');
40
        $commandTester = new CommandTester($command);
41
42
        // FIRST PASS
43
        $commandTester->execute(['command' => $command->getName()]);
44
45
        $output = <<<OUTPUT
46
+-----------+------------------------------------------------+
47
| Created:  | Padam87\AttributeBundle\Tests\Model\Subscriber |
48
+-----------+------------------------------------------------+
49
| Existing: |                                                |
50
+-----------+------------------------------------------------+
51
52
OUTPUT;
53
        $this->assertSame(str_replace(PHP_EOL, "\n", $output), $commandTester->getDisplay(true));
54
55
        // SECOND PASS
56
        $commandTester->execute(['command' => $command->getName()]);
57
58
        $output = <<<OUTPUT
59
+-----------+------------------------------------------------+
60
| Created:  |                                                |
61
+-----------+------------------------------------------------+
62
| Existing: | Padam87\AttributeBundle\Tests\Model\Subscriber |
63
+-----------+------------------------------------------------+
64
65
OUTPUT;
66
        $this->assertSame(str_replace(PHP_EOL, "\n", $output), $commandTester->getDisplay(true));
67
    }
68
}
69