Skip to content

Commit 4aefb63

Browse files
committed
refactor the attribute test
1 parent 5ff096a commit 4aefb63

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

tests/fixtures/MakeControllerAttributes/tests/GeneratedControllerTest.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Tests;
44

55
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6+
use Symfony\Component\Routing\Annotation\Route;
67

78
/**
89
* @author Jesse Rushlow <[email protected]>
@@ -14,16 +15,30 @@ class GeneratedControllerTest extends WebTestCase
1415
*/
1516
public function testControllerHasRouteAttribute(): void
1617
{
17-
self::markTestIncomplete('Im a WIP');
18-
1918
$reflected = new \ReflectionClass(\App\Controller\AttributeController::class);
2019

21-
$methodAttributes = $reflected->getMethods()[0]->getAttributes();
20+
$indexMethodAttributes = $reflected
21+
->getMethod('index')
22+
->getAttributes(Route::class)
23+
;
24+
25+
// Get the suspected Route attribute from our array of attributes.
26+
$routeAttribute = $indexMethodAttributes[0];
27+
28+
// Let's make sure the route attribute exists.
29+
self::assertSame('Symfony\Component\Routing\Annotation\Route', $routeAttribute->getName());
30+
31+
$attributeArguments = $routeAttribute->getArguments();
32+
33+
self::assertCount(2, $attributeArguments);
2234

23-
self::assertCount(1, $methodAttributes);
35+
// Test that the route path is set as the first argument in the Route attribute.
36+
self::assertSame('/attribute', $attributeArguments[0]);
2437

25-
$attributeName = $methodAttributes[0]->getName();
38+
// Test that the name of the route is set as the second argument.
39+
self::assertArrayHasKey('name', $attributeArguments);
2640

27-
self::assertSame('Symfony\Component\Routing\Annotation\Route', $attributeName);
41+
// And finally, test the the name of the route is "attribute"
42+
self::assertSame('attribute', $attributeArguments['name']);
2843
}
2944
}

0 commit comments

Comments
 (0)