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

ParameterFetcherRegistryTest::testRegistry()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 30
rs 8.8571
cc 1
eloc 18
nc 1
nop 0
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