KernelDbTestCase::tearDown()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace AppBundle\Tests;
4
5
use Symfony\Bundle\FrameworkBundle\Console\Application;
6
use Symfony\Component\Console\Input\StringInput;
7
use Symfony\Component\Console\Output\NullOutput;
8
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
9
10
abstract class KernelDbTestCase extends KernelTestCase
11
{
12
    protected $entityManager;
13
    protected $application;
14
15
    protected function setUp()
16
    {
17
        self::bootKernel();
18
19
        $this->application = new Application(self::$kernel);
20
        $this->application->setAutoExit(false);
21
22
        $this->execute('doctrine:database:drop --force --no-interaction');
23
        $this->execute('doctrine:database:create --no-interaction');
24
        $this->execute('doctrine:schema:create --no-interaction');
25
        $this->execute('doctrine:fixtures:load --no-interaction');
26
27
        $this->container = static::$kernel->getContainer();
0 ignored issues
show
Bug introduced by
The property container does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
28
29
        $this->entityManager = $this->container->get('doctrine')->getManager();
30
    }
31
32
    protected function execute($command)
33
    {
34
        $input = new StringInput($command);
35
        $output = new NullOutput();
36
37
        $this->application->run($input, $output);
38
    }
39
40
    protected function tearDown()
41
    {
42
        parent::tearDown();
43
44
        $this->entityManager->close();
45
        $this->entityManager = null; // avoid memory leaks
46
    }
47
}
48