* * 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:----RheiryKopJMehQ+5MVw3aeRgpX1udftY64Rw/nCVVlO26XpPzNSEeKhWqEh/O+l2EWZR4/GfwCW4ruyBoEYjmGV6+PIruZjzi3yLVhWkMAreAUe7Ry9x7BZKysCsD2Y+LaRSCebcsDkQXlnAPAaRSa9Az35LtT/8PUuOB2+bCkkS9y+ZX2bvdcT8T6Jzf9RykvNumkZuU0lRgSi8HpVDUGIEg7RBRlvyyxTFDudVoxbREsP9DQNXPR8mPLeJlBi1T+l4X2YD0kHhN+veIWm7PvdRhlPtAKgXBoyeyaMC0mTbusPSvR5SXFSkyGQ5QoMIdPy/ZgZTmOedd1c+ry8YOSv1KAEn0183Uf/HK0C8uGH8/d+wwqr6Lb2GqtQBtGzldaLIWBFyZNotArXYPqqmYutYssBBEWV0n4JEtyKRsl2rJ59eqFPvmHrljUIpNxvaOSCPTxXp5yXUp+L6ALklWlNxddv966i/Pqx3MwXDNlK/oCbl2iykKbt+Uv0UcasRGhql+n/Nk/YxXJ8AGU055XzPsTto/UiPeum838x2PnRsZXqyjvWg+tgD7/pnrhIjeW44te+uhnKjHNrfekXaqooMRjbe/D8p3bFiKaQo8mtyLLdY1i4r5EUicLBfccPGK/lyJy2ZVVA2UqLxC/G2Dne/A42lp+tq2dINO4BhP70=----ATTACHMENT:----NjIwMzI1NjIwNzAyOTAwMCAyMTk2OTU1MjQxNDkyOTMgNjA0OTExMDkxMzM4NTgyNA==