|
13 | 13 |
|
14 | 14 | use Psr\Container\ContainerInterface;
|
15 | 15 | use Psr\Log\LoggerInterface;
|
| 16 | +use Symfony\Component\Debug\ErrorHandler; |
| 17 | +use Symfony\Component\DependencyInjection\Container; |
16 | 18 | use Symfony\Component\HttpFoundation\Request;
|
17 | 19 | use Symfony\Component\HttpKernel\Controller\ContainerControllerResolver;
|
18 | 20 |
|
@@ -106,6 +108,48 @@ public function testNonInstantiableController()
|
106 | 108 | $this->assertSame(array(NonInstantiableController::class, 'action'), $controller);
|
107 | 109 | }
|
108 | 110 |
|
| 111 | + /** |
| 112 | + * @expectedException \LogicException |
| 113 | + * @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"? |
| 114 | + */ |
| 115 | + public function testNonConstructController() |
| 116 | + { |
| 117 | + $container = $this->getMockBuilder(Container::class)->getMock(); |
| 118 | + $container->expects($this->at(0)) |
| 119 | + ->method('has') |
| 120 | + ->with(ImpossibleConstructController::class) |
| 121 | + ->will($this->returnValue(true)) |
| 122 | + ; |
| 123 | + |
| 124 | + $container->expects($this->at(1)) |
| 125 | + ->method('has') |
| 126 | + ->with(ImpossibleConstructController::class) |
| 127 | + ->will($this->returnValue(false)) |
| 128 | + ; |
| 129 | + |
| 130 | + $container->expects($this->atLeastOnce()) |
| 131 | + ->method('getRemovedIds') |
| 132 | + ->with() |
| 133 | + ->will($this->returnValue(array(ImpossibleConstructController::class))) |
| 134 | + ; |
| 135 | + |
| 136 | + $resolver = $this->createControllerResolver(null, $container); |
| 137 | + $request = Request::create('/'); |
| 138 | + $request->attributes->set('_controller', array(ImpossibleConstructController::class, 'action')); |
| 139 | + |
| 140 | + if (\PHP_VERSION_ID < 70100) { |
| 141 | + ErrorHandler::register(); |
| 142 | + try { |
| 143 | + $resolver->getController($request); |
| 144 | + } finally { |
| 145 | + restore_error_handler(); |
| 146 | + restore_exception_handler(); |
| 147 | + } |
| 148 | + } else { |
| 149 | + $resolver->getController($request); |
| 150 | + } |
| 151 | + } |
| 152 | + |
109 | 153 | public function testNonInstantiableControllerWithCorrespondingService()
|
110 | 154 | {
|
111 | 155 | $service = new \stdClass();
|
@@ -196,3 +240,14 @@ public static function action()
|
196 | 240 | {
|
197 | 241 | }
|
198 | 242 | }
|
| 243 | + |
| 244 | +class ImpossibleConstructController |
| 245 | +{ |
| 246 | + public function __construct($toto, $controller) |
| 247 | + { |
| 248 | + } |
| 249 | + |
| 250 | + public function action() |
| 251 | + { |
| 252 | + } |
| 253 | +} |
0 commit comments