SyncSchemaCommandTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 11

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 11
dl 0
loc 56
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 14 1
B execute() 0 34 1
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