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
|
1 |
|
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 |
|
self::assertSame('test/method', $collection->get('test_method')->getMethod()); |
46
|
1 |
|
} |
47
|
|
|
|
48
|
1 |
|
protected static function getKernelClass() |
49
|
|
|
{ |
50
|
1 |
|
return Kernel::class; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|