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