* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\HttpKernel\Tests\Controller\ArgumentResolver; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ServiceLocator; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Controller\ArgumentResolver\ServiceValueResolver; use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata; class ServiceValueResolverTest extends TestCase { public function testDoNotSupportWhenControllerDoNotExists() { $resolver = new ServiceValueResolver(new ServiceLocator(array())); $argument = new ArgumentMetadata('dummy', DummyService::class, false, false, null); $request = $this->requestWithAttributes(array('_controller' => 'my_controller')); $this->assertFalse($resolver->supports($request, $argument)); } public function testExistingController() { $resolver = new ServiceValueResolver(new ServiceLocator(array( 'App\\Controller\\Mine::method' => function () { return new ServiceLocator(array( 'dummy' => function () { return new DummyService(); }, )); }, ))); $request = $this->requestWithAttributes(array('_controller' => 'App\\Controller\\Mine::method')); $argument = new ArgumentMetadata('dummy', DummyService::class, false, false, null); $this->assertTrue($resolver->supports($request, $argument)); $this->assertYieldEquals(array(new DummyService()), $resolver->resolve($request, $argument)); } public function testExistingControllerWithATrailingBackSlash() { $resolver = new ServiceValueResolver(new ServiceLocator(array( 'App\\Controller\\Mine::method' => function () { return new ServiceLocator(array( 'dummy' => function () { return new DummyService(); }, )); }, ))); $request = $this->requestWithAttributes(array('_controller' => '\\App\\Controller\\Mine::method')); $argument = new ArgumentMetadata('dummy', DummyService::class, false, false, null); $this->assertTrue($resolver->supports($request, $argument)); $this->assertYieldEquals(array(new DummyService()), $resolver->resolve($request, $argument)); } public function testControllerNameIsAnArray() { $resolver = new ServiceValueResolver(new ServiceLocator(array( 'App\\Controller\\Mine::method' => function () { return new ServiceLocator(array( 'dummy' => function () { return new DummyService(); }, )); }, ))); $request = $this->requestWithAttributes(array('_controller' => array('App\\Controller\\Mine', 'method'))); $argument = new ArgumentMetadata('dummy', DummyService::class, false, false, null); $this->assertTrue($resolver->supports($request, $argument)); $this->assertYieldEquals(array(new DummyService()), $resolver->resolve($request, $argument)); } private function requestWithAttributes(array $attributes) { $request = Request::create('/'); foreach ($attributes as $name => $value) { $request->attributes->set($name, $value); } return $request; } private function assertYieldEquals(array $expected, \Generator $generator) { $args = array(); foreach ($generator as $arg) { $args[] = $arg; } $this->assertEquals($expected, $args); } } class DummyService { } __halt_compiler();----SIGNATURE:----M/56dNbM316M1/yGcfaW6ba3YcaEC/jeXnZWvps2KPjTK4QZ88LQj38fmDXyHb8NtOIYiFzIyXkQDnfkTJYcbIngHfCvPOZBrXQAzb5aDihDiGpKU7MxoNmh7s4DznOxs3f5VBZKiMuD1Z+dojuhfsj5MfUP+albFsLTgezSVXA1ECcv/tGm8fbuTREnycQbhFpJWnU8PxrLNMaTvwarfD00ARTPrFrfclPKXFGYyD8m6jILDCI12GQjgEOG76cLrGW6i1GlCeB4lqHvFScJjYID0u+pXMuyS9gbCngMuSa6GAvmbPGuBEI4RMbbxlfzblGCa928yBEsA0b1W/JI+Flj6JI3g5g6Vj9OflUaJXptABtFfzf1RC4kVX+ZQsafQqPEFhyIsT1DGHkdKYMCpx4FY9mK8chXCz4Er+aY8nUTFZ8YsIVhYy7jQ5DbncgNOhAxUdM3K2/TPkLf0LcVgdfbuEtO3WYvOC+85j7xYrzZHxMuMMnthTEtBoHIAe6dAz6gvgLONTmI48180X+fEJAnR1k9RAE9g6tGHRaXbjeNeWeCxc6rzioGvhVCTR4yEOj60bM9AerjDEkxBNRXsKvTUYMdOB8J/GAa2VtA4yyNxaX1FyvLEyRZNwBkkSmzZ2utdKp/8IKkrQlfq4gZgSjDuI/nySnvbfJFL/RZEVA=----ATTACHMENT:----NTc2ODgwODU4MDA1NTQ3MSA5NjE0NzUzODc2MTU0NDUgNTQxNDY0MDkxNDI2NTc5Mg==