Completed
Push — master ( 488d96...39c422 )
by Alex
05:30
created

AbstractTestCase::bootKernel()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 3
nop 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A AbstractTestCase::getKernel() 0 6 1
1
<?php
2
3
/*
4
* This file is part of the OrbitaleCmsBundle package.
5
*
6
* (c) Alexandre Rock Ancelet <[email protected]>
7
*
8
* For the full copyright and license information, please view the LICENSE
9
* file that was distributed with this source code.
10
*/
11
12
namespace Orbitale\Bundle\CmsBundle\Tests\Fixtures;
13
14
use Doctrine\DBAL\Connection;
15
use Orbitale\Bundle\CmsBundle\Tests\Fixtures\TestBundle\Entity\Page;
16
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
17
use Symfony\Component\DependencyInjection\ContainerInterface;
18
use Symfony\Component\HttpKernel\KernelInterface;
19
20
/**
21
 * Class AbstractTestCase.
22
 */
23
class AbstractTestCase extends WebTestCase
24
{
25
    /**
26
     * @var ContainerInterface
27
     */
28
    protected static $container;
29
30
    public function setUp()
31
    {
32
        /** @var Connection $c */
33
        $c = static::getKernel()->getContainer()->get('doctrine')->getConnection();
34
        $c->query('delete from orbitale_cms_pages where 1');
35
        $c->query('delete from orbitale_cms_categories where 1');
36
    }
37
38
    /**
39
     * @param array $options An array of options to pass to the createKernel class
40
     *
41
     * @return KernelInterface
42
     */
43
    protected static function getKernel(array $options = []): KernelInterface
44
    {
45
        static::bootKernel($options);
46
47
        return static::$kernel;
48
    }
49
50
    /**
51
     * @param array $values
52
     *
53
     * @return Page
54
     */
55
    protected function createPage(array $values = []): Page
56
    {
57
        $page = new Page();
58
59
        foreach ($values as $key => $value) {
60
            $page->{'set'.ucfirst($key)}($value);
61
        }
62
63
        return $page;
64
    }
65
}
66