Completed
Push — fetcher_factories ( 951c99...ef2a05 )
by David
09:00
created

ParameterFetcherRegistryTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 1
c 2
b 0
f 0
lcom 0
cbo 6
dl 0
loc 33
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B testRegistry() 0 30 1
1
<?php
2
3
4
namespace Mouf\Mvc\Splash\Services;
5
6
7
use Mouf\Mvc\Splash\Fixtures\TestController2;
8
use ReflectionMethod;
9
use Zend\Diactoros\ServerRequest;
10
11
class ParameterFetcherRegistryTest extends \PHPUnit_Framework_TestCase
12
{
13
    public function testRegistry()
14
    {
15
        $registry = new ParameterFetcherRegistry();
16
        $registry->registerParameterFetcher(new SplashRequestParameterFetcher());
17
        $registry->registerParameterFetcher(new SplashRequestFetcher());
18
19
20
        $map = $registry->mapParameters(new ReflectionMethod(TestController2::class, 'completeTest'));
21
22
        $this->assertEquals(1, $map[0]['fetcherId'] );
23
        $this->assertEquals(0, $map[1]['fetcherId'] );
24
        $this->assertEquals(1, $map[2]['fetcherId'] );
25
        $this->assertEquals(1, $map[3]['fetcherId'] );
26
27
        // Now, let's use that map to retrieve data.
28
        $request = new ServerRequest([], [], '/foo/12/bar', 'GET', 'php://input',
29
            [],
30
            [],
31
            [ 'id' => 42 ]
32
        );
33
        $splashContext = new SplashRequestContext($request);
34
        $splashContext->addUrlParameter('var', 'var');
35
36
        $arguments = $registry->toArguments($splashContext, $map);
37
38
        $this->assertEquals(42, $arguments[0] );
39
        $this->assertSame($request, $arguments[1] );
40
        $this->assertEquals('var', $arguments[2] );
41
        $this->assertEquals(42, $arguments[3] );
42
    }
43
}
44