1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Symplify\ControllerAutowire\Tests\DependencyInjection\Compiler; |
4
|
|
|
|
5
|
|
|
use PHPUnit_Framework_TestCase; |
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
7
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
8
|
|
|
use Symplify\ControllerAutowire\DependencyInjection\Compiler\RegisterControllersPass; |
9
|
|
|
use Symplify\ControllerAutowire\DependencyInjection\ControllerClassMap; |
10
|
|
|
use Symplify\ControllerAutowire\HttpKernel\Controller\ControllerFinder; |
11
|
|
|
use Symplify\ControllerAutowire\SymplifyControllerAutowireBundle; |
12
|
|
|
use Symplify\ControllerAutowire\Tests\DependencyInjection\Compiler\RegisterControllersPassSource\SomeController; |
13
|
|
|
|
14
|
|
|
final class RegisterControllersPassTest extends PHPUnit_Framework_TestCase |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var RegisterControllersPass |
18
|
|
|
*/ |
19
|
|
|
private $registerControllersPass; |
20
|
|
|
|
21
|
|
|
protected function setUp() |
22
|
|
|
{ |
23
|
|
|
$controllerClassMap = new ControllerClassMap(); |
24
|
|
|
$controllerClassMap->addController('somecontroller', 'SomeController'); |
25
|
|
|
|
26
|
|
|
$controllerFinder = new ControllerFinder(); |
27
|
|
|
$this->registerControllersPass = new RegisterControllersPass($controllerClassMap, $controllerFinder); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testProcess() |
31
|
|
|
{ |
32
|
|
|
$containerBuilder = new ContainerBuilder(); |
33
|
|
|
$this->assertCount(0, $containerBuilder->getDefinitions()); |
34
|
|
|
|
35
|
|
|
$containerBuilder->prependExtensionConfig(SymplifyControllerAutowireBundle::ALIAS, [ |
36
|
|
|
'controller_dirs' => [ |
37
|
|
|
__DIR__.'/RegisterControllersPassSource', |
38
|
|
|
], |
39
|
|
|
]); |
40
|
|
|
$this->registerControllersPass->process($containerBuilder); |
41
|
|
|
|
42
|
|
|
$definitions = $containerBuilder->getDefinitions(); |
43
|
|
|
$this->assertCount(1, $definitions); |
44
|
|
|
|
45
|
|
|
/** @var Definition $controllerDefinition */ |
46
|
|
|
$controllerDefinition = array_pop($definitions); |
47
|
|
|
$this->assertInstanceOf(Definition::class, $controllerDefinition); |
48
|
|
|
|
49
|
|
|
$this->assertSame(SomeController::class, $controllerDefinition->getClass()); |
50
|
|
|
$this->assertTrue($controllerDefinition->isAutowired()); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testServiceDefinitionExists() |
54
|
|
|
{ |
55
|
|
|
$containerBuilder = new ContainerBuilder(); |
56
|
|
|
$containerBuilder->prependExtensionConfig(SymplifyControllerAutowireBundle::ALIAS, [ |
57
|
|
|
'controller_dirs' => [ |
58
|
|
|
__DIR__.'/RegisterControllersPassSource', |
59
|
|
|
], |
60
|
|
|
]); |
61
|
|
|
|
62
|
|
|
$controllerDefition = new Definition(SomeController::class); |
63
|
|
|
$containerBuilder->setDefinition( |
64
|
|
|
'symplify.controllerautowire.tests.dependencyinjection.' |
65
|
|
|
.'compiler.registercontrollerspasssource.somecontroller', |
66
|
|
|
$controllerDefition |
67
|
|
|
); |
68
|
|
|
$this->assertCount(1, $containerBuilder->getDefinitions()); |
69
|
|
|
|
70
|
|
|
$this->registerControllersPass->process($containerBuilder); |
71
|
|
|
$this->assertCount(1, $containerBuilder->getDefinitions()); |
72
|
|
|
|
73
|
|
|
$this->assertTrue($controllerDefition->isAutowired()); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|