Completed
Push — master ( 2c6719...58280f )
by Gaetano
11:02
created

CommandTest::getContainer()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 13
rs 9.4285
cc 2
eloc 8
nc 2
nop 0
1
<?php
2
3
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
4
use Symfony\Bundle\FrameworkBundle\Console\Application;
5
use Symfony\Component\Console\Output\BufferedOutput;
6
7
abstract class CommandTest extends WebTestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
{
9
    protected $dslDir =  __DIR__.'/../dsl';
10
    protected $targetBundle = 'EzPublishCoreBundle'; // it is always present :-)
11
    protected $leftovers = array();
12
13
    protected $container;
14
    protected $app;
15
    protected $output;
16
17
    protected function setUp()
18
    {
19
        $this->container = $this->getContainer();
20
21
        $this->app = new Application(static::$kernel);
22
        $this->app->setAutoExit(false);
23
        $this->output = new BufferedOutput();
24
        $this->leftovers = array();
25
    }
26
27
    protected function tearDown()
28
    {
29
        foreach($this->leftovers as $file) {
30
            unlink($file);
31
        }
32
33
        // clean buffer, just in case...
34
        $this->output->fetch();
35
    }
36
37
    protected function getContainer()
38
    {
39
        if (null !== static::$kernel) {
40
            static::$kernel->shutdown();
41
        }
42
        // run in our own test environment. Sf by default uses the 'test' one. We let phpunit.xml set it...
43
        $options = array(
44
            'environment' => $_SERVER['SYMFONY_ENV']
45
        );
46
        static::$kernel = static::createKernel($options);
47
        static::$kernel->boot();
48
        return static::$kernel->getContainer();
49
    }
50
}
51