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 |
|
|
|
|
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
|
|
|
|
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 methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.