|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bankiru\Api\Rpc\Test\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use Bankiru\Api\Rpc\Routing\MethodCollection; |
|
6
|
|
|
use Bankiru\Api\Rpc\Routing\Router; |
|
7
|
|
|
use Bankiru\Api\Rpc\Test\Kernel; |
|
8
|
|
|
use Bankiru\Api\Rpc\Test\Rpc\TestController; |
|
9
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
|
10
|
|
|
use Symfony\Component\Routing\RequestContext; |
|
11
|
|
|
|
|
12
|
|
|
class RoutingTest extends WebTestCase |
|
13
|
|
|
{ |
|
14
|
1 |
|
public function testRouting() |
|
15
|
|
|
{ |
|
16
|
1 |
|
$client = self::createClient(); |
|
17
|
1 |
|
$router = $client->getContainer()->get('router'); |
|
18
|
1 |
|
$context = new RequestContext(); |
|
19
|
1 |
|
$context->setMethod('POST'); |
|
20
|
1 |
|
$router->setContext($context); |
|
21
|
1 |
|
$match = $router->match('/test/'); |
|
22
|
1 |
|
self::assertArrayHasKey('_controller', $match); |
|
23
|
1 |
|
self::assertSame(TestController::class . '::rpcAction', $match['_controller']); |
|
24
|
1 |
|
self::assertSame('test', $match['_route']); |
|
25
|
1 |
|
} |
|
26
|
|
|
|
|
27
|
1 |
|
public function testRpcRouterCollection() |
|
28
|
|
|
{ |
|
29
|
1 |
|
$client = self::createClient(); |
|
30
|
|
|
/** @var Router $router */ |
|
31
|
1 |
|
$router = $client->getContainer()->get('rpc_server.endpoint_router.test'); |
|
32
|
1 |
|
self::assertNotNull($router); |
|
33
|
|
|
/** @var MethodCollection $collection */ |
|
34
|
1 |
|
$collection = $router->getMethodCollection(); |
|
35
|
1 |
|
self::assertNotNull($router); |
|
36
|
1 |
|
self::assertInstanceOf(MethodCollection::class, $collection); |
|
37
|
|
|
|
|
38
|
1 |
|
self::assertTrue($collection->has('test_method')); |
|
39
|
1 |
|
$route = $collection->get('test_method'); |
|
40
|
1 |
|
self::assertSame('test/method', $route->getMethod()); |
|
41
|
|
|
|
|
42
|
1 |
|
self::assertContains('Default', $route->getContext()); |
|
43
|
1 |
|
self::assertContains('test', $route->getContext()); |
|
44
|
1 |
|
self::assertTrue($route->includeDefaultContext()); |
|
45
|
|
|
|
|
46
|
1 |
|
$route = $collection->get('test_inheritance'); |
|
47
|
1 |
|
self::assertSame('test/non-inherited', $route->getMethod()); |
|
48
|
|
|
|
|
49
|
1 |
|
self::assertCount(2, $route->getContext()); |
|
50
|
1 |
|
self::assertContains('Default', $route->getContext()); |
|
51
|
1 |
|
self::assertNotContains('test', $route->getContext()); |
|
52
|
1 |
|
self::assertContains('own', $route->getContext()); |
|
53
|
1 |
|
self::assertTrue($route->includeDefaultContext()); |
|
54
|
|
|
|
|
55
|
1 |
|
$route = $collection->get('annotation'); |
|
56
|
1 |
|
self::assertSame('annotation', $route->getMethod()); |
|
57
|
|
|
|
|
58
|
1 |
|
self::assertNotContains('Default', $route->getContext()); |
|
59
|
1 |
|
self::assertFalse($route->includeDefaultContext()); |
|
60
|
1 |
|
self::assertContains('annotation-non-inherit', $route->getContext()); |
|
61
|
1 |
|
self::assertCount(1, $route->getContext()); |
|
62
|
1 |
|
} |
|
63
|
|
|
|
|
64
|
1 |
|
protected static function getKernelClass() |
|
65
|
|
|
{ |
|
66
|
1 |
|
return Kernel::class; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|