1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Devmachine\Bundle\ServicesInjectorBundle\Tests\Functional; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Annotations\AnnotationRegistry; |
6
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; |
7
|
|
|
use Symfony\Component\HttpFoundation\Request; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @group functional |
11
|
|
|
*/ |
12
|
|
|
class DevmachineServicesInjectorBundleTest extends KernelTestCase |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject |
16
|
|
|
*/ |
17
|
|
|
private $serviceLocator; |
18
|
|
|
|
19
|
|
|
public static function setUpBeforeClass() |
20
|
|
|
{ |
21
|
|
|
AnnotationRegistry::registerLoader('class_exists'); |
|
|
|
|
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function setUp() |
25
|
|
|
{ |
26
|
|
|
static::bootKernel(); |
27
|
|
|
|
28
|
|
|
$this->serviceLocator = $this->getMock('Devmachine\Bundle\ServicesInjectorBundle\ServiceLocator\ServiceLocator'); |
29
|
|
|
|
30
|
|
|
static::$kernel->getContainer()->set( |
31
|
|
|
'devmachine_services_injector.service_locator.container', |
32
|
|
|
$this->serviceLocator |
33
|
|
|
); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @test |
38
|
|
|
*/ |
39
|
|
|
public function it_injects_locator_into_first_action() |
40
|
|
|
{ |
41
|
|
|
$this->serviceLocator |
42
|
|
|
->expects($this->exactly(2)) |
43
|
|
|
->method('get') |
44
|
|
|
->withConsecutive( |
45
|
|
|
[$this->equalTo('twig')], |
46
|
|
|
[$this->equalTo('translator')] |
47
|
|
|
) |
48
|
|
|
; |
49
|
|
|
|
50
|
|
|
static::$kernel->handle($this->createRequest('firstAction')); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @test |
55
|
|
|
*/ |
56
|
|
|
public function it_injects_locator_into_second_action() |
57
|
|
|
{ |
58
|
|
|
$this->serviceLocator |
59
|
|
|
->expects($this->exactly(4)) |
60
|
|
|
->method('get') |
61
|
|
|
->withConsecutive( |
62
|
|
|
[$this->equalTo('twig')], |
63
|
|
|
[$this->equalTo('form.factory')], |
64
|
|
|
[$this->equalTo('router')], |
65
|
|
|
[$this->equalTo('translator')] |
66
|
|
|
) |
67
|
|
|
; |
68
|
|
|
|
69
|
|
|
static::$kernel->handle($this->createRequest('secondAction')); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @test |
74
|
|
|
* |
75
|
|
|
* @expectedException \InvalidArgumentException |
76
|
|
|
* @expectedExceptionMessage Service with alias "translator" is not registered. |
77
|
|
|
*/ |
78
|
|
|
public function it_throws_exception_on_third_action() |
79
|
|
|
{ |
80
|
|
|
$this->serviceLocator |
81
|
|
|
->expects($this->never()) |
82
|
|
|
->method('get') |
83
|
|
|
; |
84
|
|
|
|
85
|
|
|
static::$kernel->handle($this->createRequest('thirdAction')); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
protected static function getKernelClass() |
89
|
|
|
{ |
90
|
|
|
return __NAMESPACE__.'\\TestKernel'; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param string $methodName |
95
|
|
|
* |
96
|
|
|
* @return Request |
97
|
|
|
*/ |
98
|
|
|
private function createRequest($methodName) |
99
|
|
|
{ |
100
|
|
|
return new Request([], [], ['_controller' => [new TestController(), $methodName]]); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.