public function testIntegrationNoUser()
 {
     $token = $this->getMock(TokenInterface::class);
     $tokenStorage = new TokenStorage();
     $tokenStorage->setToken($token);
     $argumentResolver = new ArgumentResolver(null, array(new SecurityUserValueResolver($tokenStorage), new DefaultValueResolver()));
     $this->assertSame(array(null), $argumentResolver->getArguments(Request::create('/'), function (UserInterface $user = null) {
     }));
 }
Пример #2
0
 /**
  * @requires PHP 7.1
  */
 public function testGetNullableArgumentsWithDefaults()
 {
     $request = Request::create('/');
     $request->attributes->set('mandatory', 'mandatory');
     $controller = array(new NullableController(), 'action');
     $this->assertEquals(array(null, null, 'value', 'mandatory'), self::$resolver->getArguments($request, $controller));
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function register(Container $app)
 {
     $app['resolver'] = function ($app) {
         if (Kernel::VERSION_ID >= 30100) {
             return new SfControllerResolver($app['logger']);
         }
         return new ControllerResolver($app, $app['logger']);
     };
     if (Kernel::VERSION_ID >= 30100) {
         $app['argument_metadata_factory'] = function ($app) {
             return new ArgumentMetadataFactory();
         };
         $app['argument_value_resolvers'] = function ($app) {
             if (Kernel::VERSION_ID < 30200) {
                 return array(new AppArgumentValueResolver($app), new RequestAttributeValueResolver(), new RequestValueResolver(), new DefaultValueResolver(), new VariadicValueResolver());
             }
             return array_merge(array(new AppArgumentValueResolver($app)), ArgumentResolver::getDefaultArgumentValueResolvers());
         };
     }
     $app['argument_resolver'] = function ($app) {
         if (Kernel::VERSION_ID >= 30100) {
             return new ArgumentResolver($app['argument_metadata_factory'], $app['argument_value_resolvers']);
         }
     };
     $app['kernel'] = function ($app) {
         return new HttpKernel($app['dispatcher'], $app['resolver'], $app['request_stack'], $app['argument_resolver']);
     };
     $app['request_stack'] = function () {
         return new RequestStack();
     };
     $app['dispatcher'] = function () {
         return new EventDispatcher();
     };
     $app['callback_resolver'] = function ($app) {
         return new CallbackResolver($app);
     };
 }
Пример #4
0
 /**
  * @requires PHP 5.6
  * @expectedException \InvalidArgumentException
  */
 public function testGetArgumentWithoutArray()
 {
     $factory = new ArgumentMetadataFactory();
     $valueResolver = $this->getMock(ArgumentValueResolverInterface::class);
     $resolver = new ArgumentResolver($factory, array($valueResolver));
     $valueResolver->expects($this->any())->method('supports')->willReturn(true);
     $valueResolver->expects($this->any())->method('resolve')->willReturn('foo');
     $request = Request::create('/');
     $request->attributes->set('foo', 'foo');
     $request->attributes->set('bar', 'foo');
     $controller = array($this, 'controllerWithFooAndDefaultBar');
     $resolver->getArguments($request, $controller);
 }