|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bankiru\Api\Rpc\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use Bankiru\Api\Rpc\Http\Routing\EndpointRouteLoader; |
|
6
|
|
|
use Symfony\Component\Config\Loader\LoaderResolver; |
|
7
|
|
|
use Symfony\Component\Routing\RouteCollection; |
|
8
|
|
|
|
|
9
|
|
|
class EndpointRouteLoaderTest extends \PHPUnit_Framework_TestCase |
|
10
|
|
|
{ |
|
11
|
1 |
|
public function testLoader() |
|
12
|
|
|
{ |
|
13
|
|
|
$public = [ |
|
14
|
1 |
|
'path' => '/', |
|
15
|
|
|
'defaults' => [ |
|
16
|
1 |
|
'_format' => 'json', |
|
17
|
1 |
|
'_locale' => 'ru', |
|
18
|
1 |
|
], |
|
19
|
1 |
|
]; |
|
20
|
|
|
|
|
21
|
|
|
$admin = [ |
|
22
|
1 |
|
'path' => '/admin/', |
|
23
|
1 |
|
'defaults' => [ |
|
24
|
1 |
|
'_format' => 'json', |
|
25
|
1 |
|
'_locale' => 'ru', |
|
26
|
1 |
|
], |
|
27
|
1 |
|
]; |
|
28
|
|
|
|
|
29
|
|
|
$test = [ |
|
30
|
1 |
|
'path' => '/test/', |
|
31
|
|
|
'defaults' => [ |
|
32
|
1 |
|
'_format' => 'xml', |
|
33
|
1 |
|
'_locale' => 'ru', |
|
34
|
1 |
|
], |
|
35
|
1 |
|
]; |
|
36
|
|
|
|
|
37
|
1 |
|
$loader = new EndpointRouteLoader(); |
|
38
|
1 |
|
$resolver = new LoaderResolver([$loader]); |
|
39
|
1 |
|
$loader->setResolver($resolver); |
|
40
|
|
|
|
|
41
|
1 |
|
$loader->addEndpoint('public', $public); |
|
42
|
1 |
|
$loader->addEndpoint('admin', $admin); |
|
43
|
1 |
|
$loader->addEndpoint('test', $test); |
|
44
|
|
|
|
|
45
|
1 |
|
$realLoader = $resolver->resolve('.', 'endpoint'); |
|
46
|
|
|
|
|
47
|
|
|
/** @var RouteCollection $collection */ |
|
48
|
1 |
|
$collection = $realLoader->load('.', 'endpoint'); |
|
49
|
|
|
|
|
50
|
1 |
|
$publicRoute = $collection->get('public'); |
|
51
|
1 |
|
self::assertNotNull($publicRoute); |
|
52
|
1 |
|
$adminRoute = $collection->get('admin'); |
|
53
|
1 |
|
self::assertNotNull($adminRoute); |
|
54
|
1 |
|
$testRoute = $collection->get('test'); |
|
55
|
1 |
|
self::assertNotNull($testRoute); |
|
56
|
|
|
|
|
57
|
1 |
|
self::assertEquals('json', $publicRoute->getDefault('_format')); |
|
58
|
1 |
|
self::assertEquals('json', $adminRoute->getDefault('_format')); |
|
59
|
1 |
|
self::assertEquals('xml', $testRoute->getDefault('_format')); |
|
60
|
|
|
|
|
61
|
1 |
|
self::assertEquals('ru', $publicRoute->getDefault('_locale')); |
|
62
|
1 |
|
self::assertEquals('ru', $adminRoute->getDefault('_locale')); |
|
63
|
1 |
|
self::assertEquals('ru', $testRoute->getDefault('_locale')); |
|
64
|
|
|
|
|
65
|
|
|
try { |
|
66
|
1 |
|
$realLoader->load('.', 'endpoint'); |
|
67
|
1 |
|
} catch (\LogicException $e) { |
|
68
|
1 |
|
self::assertSame('Endpoint loader is already loaded', $e->getMessage()); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
try { |
|
72
|
1 |
|
$loader->addEndpoint('public', $public); |
|
73
|
1 |
|
} catch (\LogicException $e) { |
|
74
|
1 |
|
self::assertSame('Endpoint loader is already configured', $e->getMessage()); |
|
75
|
|
|
} |
|
76
|
1 |
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|