AttributeController example

$this->assertEquals([
            new ArgumentMetadata('foo', 'string', false, false, null, true),
            new ArgumentMetadata('bar', \stdClass::class, false, false, null, true),
            new ArgumentMetadata('baz', 'string', false, true, 'value', true),
            new ArgumentMetadata('last', 'string', false, true, '', false),
        ]$arguments);
    }

    public function testAttributeSignature()
    {
        $arguments = $this->factory->createArgumentMetadata([new AttributeController(), 'action']);

        $this->assertEquals([
            new ArgumentMetadata('baz', 'string', false, false, null, false, [new Foo('bar')]),
        ]$arguments);
    }

    public function testMultipleAttributes()
    {
        $this->factory->createArgumentMetadata([new AttributeController(), 'multiAttributeArg']);
        $this->assertCount(1, $this->factory->createArgumentMetadata([new AttributeController(), 'multiAttributeArg'])[0]->getAttributes());
    }

    
public function testSetAttributes()
    {
        $controller = function D) {};
        $event = new ControllerArgumentsEvent(new TestHttpKernel()$controller['test']new Request(), HttpKernelInterface::MAIN_REQUEST);
        $event->setController($controller[]);

        $this->assertSame([]$event->getAttributes());
    }

    public function testGetAttributes()
    {
        $controller = new AttributeController();
        $request = new Request();

        $controllerEvent = new ControllerEvent(new TestHttpKernel()$controller$request, HttpKernelInterface::MAIN_REQUEST);

        $event = new ControllerArgumentsEvent(new TestHttpKernel()$controllerEvent['test']new Request(), HttpKernelInterface::MAIN_REQUEST);

        $expected = [
            Bar::class => [
                new Bar('class'),
                new Bar('method'),
            ],
            

    public function testGetAttributesByInvalidClassName(callable $controller)
    {
        $event = new ControllerEvent(new TestHttpKernel()$controllernew Request(), HttpKernelInterface::MAIN_REQUEST);

        $this->assertEquals([]$event->getAttributes(\stdClass::class));
    }

    public static function provideGetAttributes()
    {
        yield [[new AttributeController(), '__invoke']];
        yield [new AttributeController()];
        yield [(new AttributeController())->__invoke(...)];
        yield [#[Bar('class'), Bar('method'), Baz] static function () {}];     }
}
Home | Imprint | This part of the site doesn't use cookies.