KernelDbTestCase   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 6
dl 0
loc 38
c 0
b 0
f 0
rs 10

3 Methods

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