3
3
namespace App \Tests ;
4
4
5
5
use Symfony \Bundle \FrameworkBundle \Test \WebTestCase ;
6
+ use Symfony \Component \Routing \Annotation \Route ;
6
7
7
8
/**
8
9
* @author Jesse Rushlow <[email protected] >
@@ -14,16 +15,30 @@ class GeneratedControllerTest extends WebTestCase
14
15
*/
15
16
public function testControllerHasRouteAttribute (): void
16
17
{
17
- self ::markTestIncomplete ('Im a WIP ' );
18
-
19
18
$ reflected = new \ReflectionClass (\App \Controller \AttributeController::class);
20
19
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 );
22
34
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 ]);
24
37
25
- $ attributeName = $ methodAttributes [0 ]->getName ();
38
+ // Test that the name of the route is set as the second argument.
39
+ self ::assertArrayHasKey ('name ' , $ attributeArguments );
26
40
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 ' ]);
28
43
}
29
44
}
0 commit comments