-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathReflectorTest.php
135 lines (130 loc) · 4.31 KB
/
ReflectorTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
/*
* This file is part of Aplus Framework Routing Library.
*
* (c) Natan Felles <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Tests\Routing;
use Framework\Routing\Reflector;
use PHPUnit\Framework\TestCase;
use Tests\Routing\Support\ChildClass;
use Tests\Routing\Support\UsersRouteActionsPresenter;
use Tests\Routing\Support\UsersRouteActionsResource;
use Tests\Routing\Support\WithoutRouteActions;
final class ReflectorTest extends TestCase
{
public function testWithoutRouteActions() : void
{
$reflector = new Reflector(new WithoutRouteActions());
self::assertSame([], $reflector->getRoutes());
}
public function testWithoutOrigins() : void
{
$reflector = new Reflector(new UsersRouteActionsPresenter());
self::assertContains([
'origins' => [],
'methods' => ['GET'],
'path' => '/users',
'arguments' => '*',
'name' => null,
'action' => UsersRouteActionsPresenter::class . '::index',
], $reflector->getRoutes());
self::assertContains([
'origins' => [],
'methods' => ['POST'],
'path' => '/users',
'arguments' => '*',
'name' => null,
'action' => UsersRouteActionsPresenter::class . '::create',
], $reflector->getRoutes());
self::assertContains([
'origins' => [],
'methods' => ['PATCH'],
'path' => '/users',
'arguments' => '*',
'name' => 'repeated',
'action' => UsersRouteActionsPresenter::class . '::create',
], $reflector->getRoutes());
self::assertContains([
'origins' => [],
'methods' => ['POST'],
'path' => '/users/{int}/delete',
'arguments' => '*',
'name' => null,
'action' => UsersRouteActionsPresenter::class . '::delete',
], $reflector->getRoutes());
}
public function testWithOrigins() : void
{
$reflector = new Reflector(UsersRouteActionsResource::class);
self::assertContains([
'origins' => [
'http://foo.com',
],
'methods' => ['GET'],
'path' => '/users',
'arguments' => '*',
'name' => null,
'action' => UsersRouteActionsResource::class . '::index',
], $reflector->getRoutes());
self::assertContains([
'origins' => [
'http://api.domain.xyz',
'http://domain.com',
],
'methods' => ['DELETE'],
'path' => '/users/{int}',
'arguments' => '0',
'name' => 'users.delete',
'action' => UsersRouteActionsResource::class . '::delete',
], $reflector->getRoutes());
}
public function testInChildClass() : void
{
$reflector = new Reflector(new ChildClass());
self::assertContains([
'origins' => [
'http://bar.xyz',
],
'methods' => ['GET'],
'path' => '/hello',
'arguments' => '*',
'name' => null,
'action' => ChildClass::class . '::hello',
], $reflector->getRoutes());
self::assertContains([
'origins' => [
'xxx',
],
'methods' => ['GET'],
'path' => '/replace-origin',
'arguments' => '*',
'name' => null,
'action' => ChildClass::class . '::replaceOrigin',
], $reflector->getRoutes());
self::assertContains([
'origins' => [
'xxx',
'yyy',
],
'methods' => ['GET'],
'path' => '/replace-origin-2',
'arguments' => '*',
'name' => null,
'action' => ChildClass::class . '::replaceOrigin2',
], $reflector->getRoutes());
self::assertContains([
'origins' => [
'http://bar.xyz',
],
'methods' => ['GET'],
'path' => '/bye',
'arguments' => '*',
'name' => null,
'action' => ChildClass::class . '::bye',
], $reflector->getRoutes());
}
}