Completed
Push — master ( b8af2d...8a7c66 )
by Sander
242:09 queued 202:53
created

BaseTestCase   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 51
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A bootKernel() 0 19 1
A getContainer() 0 4 1
A tearDown() 0 4 1
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 9 and the first side effect is on line 7.

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
namespace Kunstmaan\TranslatorBundle\Tests\unit;
3
4
use AppKernel;
5
use Symfony\Component\DependencyInjection\ContainerInterface;
6
7
include __DIR__ . '/app/AppKernel.php';
8
9
abstract class BaseTestCase extends \PHPUnit_Framework_TestCase
10
{
11
    /**
12
     * @var ContainerInterface
13
     */
14
    public $container;
15
16
    /**
17
     * @var AppKernel
18
     */
19
    public $kernel;
20
21
    public $connection;
22
    public $em;
23
    public static $databaseCreated = false;
24
25
    public function setUp()
26
    {
27
        $this->bootKernel();
28
    }
29
30
    private function bootKernel()
31
    {
32
        $this->kernel = new AppKernel('phpunit', true);
33
        $this->kernel->boot();
34
        $this->container = $this->kernel->getContainer();
35
36
        $em = $this->kernel->getContainer()->get('doctrine.orm.default_entity_manager');
37
        $meta = $em->getMetadataFactory()->getAllMetadata();
38
        $tool = new \Doctrine\ORM\Tools\SchemaTool($em);
39
        $tool->dropSchema($meta);
40
        $tool->createSchema($meta);
41
42
        // insert fixtures
43
        $fixtures = array(__DIR__ . '/files/fixtures.yml');
44
        $em = $this->kernel->getContainer()->get('doctrine.orm.default_entity_manager');
45
        $objects = \Nelmio\Alice\Fixtures::load($fixtures, $em);
46
        $persister = new \Nelmio\Alice\Persister\Doctrine($em);
47
        $persister->persist($objects);
48
    }
49
50
    public function getContainer()
51
    {
52
        return $this->container;
53
    }
54
55
    public function tearDown()
56
    {
57
        $this->kernel->shutdown();
58
    }
59
}
60