Skip to content

[HttpKernel] Controller Attributes #45457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Refactor fixtures of ArgumentMetadata tests
  • Loading branch information
codedmonkey committed Feb 17, 2022
commit d83270d2083778206a45ebc070aa1561900edc3f
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadataFactory;
use Symfony\Component\HttpKernel\Tests\Fixtures\Attribute\Foo;
use Symfony\Component\HttpKernel\Tests\Fixtures\Controller\AttributeController;
use Symfony\Component\HttpKernel\Tests\Fixtures\Attribute\FooParam;
use Symfony\Component\HttpKernel\Tests\Fixtures\Controller\ArgumentAttributeController;
use Symfony\Component\HttpKernel\Tests\Fixtures\Controller\BasicTypesController;
use Symfony\Component\HttpKernel\Tests\Fixtures\Controller\NullableController;
use Symfony\Component\HttpKernel\Tests\Fixtures\Controller\VariadicController;
Expand Down Expand Up @@ -121,24 +121,24 @@ public function testNullableTypesSignature()

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

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

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

public function testIssue41478()
{
$arguments = $this->factory->createArgumentMetadata([new AttributeController(), 'issue41478']);
$arguments = $this->factory->createArgumentMetadata([new ArgumentAttributeController(), 'issue41478']);
$this->assertEquals([
new ArgumentMetadata('baz', 'string', false, false, null, false, [new Foo('bar')]),
new ArgumentMetadata('baz', 'string', false, false, null, false, [new FooParam('bar')]),
new ArgumentMetadata('bat', 'string', false, false, null, false, []),
], $arguments);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
use Symfony\Component\HttpKernel\Tests\Fixtures\Attribute\Foo;
use Symfony\Component\HttpKernel\Tests\Fixtures\Attribute\FooParam;

class ArgumentMetadataTest extends TestCase
{
Expand Down Expand Up @@ -45,7 +45,7 @@ public function testDefaultValueUnavailable()

public function testGetAttributes()
{
$argument = new ArgumentMetadata('foo', 'string', false, true, 'default value', true, [new Foo('bar')]);
$this->assertEquals([new Foo('bar')], $argument->getAttributes());
$argument = new ArgumentMetadata('foo', 'string', false, true, 'default value', true, [new FooParam('bar')]);
$this->assertEquals([new FooParam('bar')], $argument->getAttributes());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Symfony\Component\HttpKernel\Tests\Fixtures\Attribute;

#[\Attribute(\Attribute::TARGET_PARAMETER)]
class Foo
class FooParam
{
private $foo;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@

namespace Symfony\Component\HttpKernel\Tests\Fixtures\Controller;

use Symfony\Component\HttpKernel\Tests\Fixtures\Attribute\Foo;
use Symfony\Component\HttpKernel\Tests\Fixtures\Attribute\FooParam;

class AttributeController
class ArgumentAttributeController
{
public function action(#[Foo('bar')] string $baz)
public function action(#[FooParam('bar')] string $baz)
{
}

public function multiAttributeArg(#[Foo('bar'), Undefined('bar')] string $baz)
public function multiAttributeArg(#[FooParam('bar'), Undefined('bar')] string $baz)
{
}

public function issue41478(#[Foo('bar')] string $baz, string $bat)
public function issue41478(#[FooParam('bar')] string $baz, string $bat)
{
}
}
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy