BaseBundleTestCase   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 89.66%

Importance

Changes 0
Metric Value
wmc 9
c 0
b 0
f 0
lcom 1
cbo 3
dl 0
loc 78
ccs 26
cts 29
cp 0.8966
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
getBundleClass() 0 1 ?
A bootKernel() 0 10 2
A getContainer() 0 4 1
A createKernel() 0 14 2
A ensureKernelShutdown() 0 10 3
A tearDown() 0 4 1
1
<?php
2
3
namespace Nyholm\BundleTest;
4
5
use PHPUnit\Framework\TestCase;
6
use Symfony\Component\DependencyInjection\ResettableContainerInterface;
7
use Symfony\Component\HttpKernel\Kernel;
8
9
/**
10
 * @author Tobias Nyholm <[email protected]>
11
 */
12
abstract class BaseBundleTestCase extends TestCase
13
{
14
    /**
15
     * @var AppKernel
16
     */
17
    private $kernel;
18
19
    /**
20
     * @return string
21
     */
22
    abstract protected function getBundleClass();
23
24
    /**
25
     * Boots the Kernel for this test.
26
     *
27
     * @param array $options
0 ignored issues
show
Bug introduced by
There is no parameter named $options. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
28
     */
29 1
    protected function bootKernel()
30
    {
31 1
        $this->ensureKernelShutdown();
32
33 1
        if (null === $this->kernel) {
34 1
            $this->createKernel();
35 1
        }
36
37 1
        $this->kernel->boot();
38 1
    }
39
40
    /**
41
     * @return \Symfony\Component\DependencyInjection\ContainerInterface
42
     */
43 1
    protected function getContainer()
44
    {
45 1
        return $this->kernel->getContainer();
46
    }
47
48
    /**
49
     * Get a kernel which you may configure with your bundle and services.
50
     *
51
     * @return AppKernel
52
     */
53 1
    protected function createKernel()
54
    {
55 1
        if (!class_exists(Kernel::class)) {
56
            throw new \LogicException('You must install symfony/symfony to run the bundle test.');
57
        }
58
59 1
        require_once __DIR__.'/AppKernel.php';
60 1
        $class = 'Nyholm\BundleTest\AppKernel';
61
62 1
        $this->kernel = new $class(uniqid('cache'));
63 1
        $this->kernel->addBundle($this->getBundleClass());
64
65 1
        return $this->kernel;
66
    }
67
68
    /**
69
     * Shuts the kernel down if it was used in the test.
70
     */
71 1
    private function ensureKernelShutdown()
72
    {
73 1
        if (null !== $this->kernel) {
74 1
            $container = $this->kernel->getContainer();
75 1
            $this->kernel->shutdown();
76 1
            if ($container instanceof ResettableContainerInterface) {
77
                $container->reset();
78
            }
79 1
        }
80 1
    }
81
82
    /**
83
     * Clean up Kernel usage in this test.
84
     */
85 1
    protected function tearDown()
86
    {
87 1
        $this->ensureKernelShutdown();
88 1
    }
89
}
90