|
13 | 13 |
|
14 | 14 | use Psr\Container\ContainerInterface;
|
15 | 15 | use Psr\Log\LoggerInterface;
|
| 16 | +use Symfony\Component\DependencyInjection\ContainerBuilder; |
16 | 17 | use Symfony\Component\HttpFoundation\Request;
|
17 | 18 | use Symfony\Component\HttpKernel\Controller\ContainerControllerResolver;
|
18 | 19 |
|
@@ -106,6 +107,38 @@ public function testNonInstantiableController()
|
106 | 107 | $this->assertSame(array(NonInstantiableController::class, 'action'), $controller);
|
107 | 108 | }
|
108 | 109 |
|
| 110 | + /** |
| 111 | + * @expectedException \LogicException |
| 112 | + * @expectedExceptionMessage Controller "Symfony\Component\HttpKernel\Tests\Controller\ImpossibleConstructController" cannot be fetched from the container because it is private. Did you forget to tag the service with "controller.service_arguments"? |
| 113 | + */ |
| 114 | + public function testNonConstructController() |
| 115 | + { |
| 116 | + $container = $this->getMockBuilder(ContainerBuilder::class)->getMock(); |
| 117 | + $container->expects($this->at(0)) |
| 118 | + ->method('has') |
| 119 | + ->with(ImpossibleConstructController::class) |
| 120 | + ->will($this->returnValue(true)) |
| 121 | + ; |
| 122 | + |
| 123 | + $container->expects($this->at(1)) |
| 124 | + ->method('has') |
| 125 | + ->with(ImpossibleConstructController::class) |
| 126 | + ->will($this->returnValue(false)) |
| 127 | + ; |
| 128 | + |
| 129 | + $container->expects($this->atLeastOnce()) |
| 130 | + ->method('getRemovedIds') |
| 131 | + ->with() |
| 132 | + ->will($this->returnValue(array(ImpossibleConstructController::class))) |
| 133 | + ; |
| 134 | + |
| 135 | + $resolver = $this->createControllerResolver(null, $container); |
| 136 | + $request = Request::create('/'); |
| 137 | + $request->attributes->set('_controller', array(ImpossibleConstructController::class, 'action')); |
| 138 | + |
| 139 | + $resolver->getController($request); |
| 140 | + } |
| 141 | + |
109 | 142 | public function testNonInstantiableControllerWithCorrespondingService()
|
110 | 143 | {
|
111 | 144 | $service = new \stdClass();
|
@@ -196,3 +229,14 @@ public static function action()
|
196 | 229 | {
|
197 | 230 | }
|
198 | 231 | }
|
| 232 | + |
| 233 | +class ImpossibleConstructController |
| 234 | +{ |
| 235 | + public function __construct($toto, $controller) |
| 236 | + { |
| 237 | + } |
| 238 | + |
| 239 | + public function action() |
| 240 | + { |
| 241 | + } |
| 242 | +} |
0 commit comments