Completed
Push — master ( 58bdf2...4883e1 )
by Pavel
03:39
created

EndpointRouteLoaderTest::testLoader()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 66
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 44
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 66
ccs 44
cts 44
cp 1
rs 9.3191
cc 3
eloc 44
nc 4
nop 0
crap 3

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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