KernelAwareTest::getMetadatas()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 11 and the first side effect is on line 5.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
namespace SkautisBundle\Tests\Integration;
4
5
require_once dirname(__DIR__) . '/../../../../app/AppKernel.php';
6
7
/**
8
 * Test case class helpful with Entity tests requiring the database interaction.
9
 * For regular entity tests it's better to extend standard \PHPUnit_Framework_TestCase instead.
10
 */
11
abstract class KernelAwareTest extends \PHPUnit_Framework_TestCase
12
{
13
    /**
14
     * @var Symfony\Component\HttpKernel\AppKernel
15
     */
16
    protected $kernel;
17
18
    /**
19
     * @var Doctrine\ORM\EntityManager
20
     */
21
    protected $entityManager;
22
23
    /**
24
     * @var Symfony\Component\DependencyInjection\Container
25
     */
26
    protected $container;
27
28
    /**
29
     * @return null
30
     */
31
    public function setUp()
32
    {
33
        $this->kernel = new \AppKernel('test', true);
0 ignored issues
show
Documentation Bug introduced by
It seems like new \AppKernel('test', true) of type object<AppKernel> is incompatible with the declared type object<SkautisBundle\Tes...t\HttpKernel\AppKernel> of property $kernel.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
34
        $this->kernel->boot();
35
36
        $this->container = $this->kernel->getContainer();
37
        $this->entityManager = $this->container->get('doctrine')->getManager();
38
39
        $this->generateSchema();
40
41
        parent::setUp();
42
    }
43
44
    /**
45
     * @return null
46
     */
47
    public function tearDown()
48
    {
49
        $this->kernel->shutdown();
50
51
        parent::tearDown();
52
    }
53
54
    /**
55
     * @return null
56
     */
57
    protected function generateSchema()
58
    {
59
        $metadatas = $this->getMetadatas();
60
61
        if (!empty($metadatas)) {
62
            $tool = new \Doctrine\ORM\Tools\SchemaTool($this->entityManager);
63
            $tool->dropSchema($metadatas);
64
            $tool->createSchema($metadatas);
65
        }
66
    }
67
68
    /**
69
     * @return array
70
     */
71
    protected function getMetadatas()
72
    {
73
        return $this->entityManager->getMetadataFactory()->getAllMetadata();
74
    }
75
}
76