TestCase::get()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace TreeHouse\IoBundle\Test;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
7
use Symfony\Component\DependencyInjection\ContainerInterface;
8
use Symfony\Component\Yaml\Yaml;
9
10
class TestCase extends WebTestCase
11
{
12
    /**
13
     * Shortcut to the Container's get method.
14
     *
15
     * @param string $serviceId
16
     *
17
     * @return object
18
     */
19
    public function get($serviceId)
20
    {
21
        return $this->getContainer()->get($serviceId);
22
    }
23
24
    /**
25
     * @param array $options Kernel options
26
     *
27
     * @return ContainerInterface
28
     */
29
    public static function getContainer(array $options = [])
30
    {
31
        if (null === static::$kernel) {
32
            static::$kernel = static::createKernel($options);
33
        }
34
35
        static::$kernel->boot();
36
37
        return static::$kernel->getContainer();
38
    }
39
40
    /**
41
     * @return EntityManagerInterface
42
     */
43
    public function getEntityManager()
44
    {
45
        return $this->getContainer()->get('doctrine')->getManager();
46
    }
47
48
    /**
49
     * Returns fixtures of a type.
50
     *
51
     * @param string $type
52
     *
53
     * @return array
54
     */
55
    public function getFixtures($type)
56
    {
57
        $loader = new Yaml();
58
59
        return $loader->parse(sprintf(__DIR__ . '/../Resources/fixtures/%s.yml', $type));
60
    }
61
}
62