Completed
Push — fetcher_factories ( 10a56f...fd93ea )
by David
13:44
created

testSplashRequestParameterFetcher()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 38
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 38
rs 8.8571
cc 1
eloc 23
nc 1
nop 0
1
<?php
2
3
namespace Mouf\Mvc\Splash\Services;
4
5
use Mouf\Mvc\Splash\Fixtures\TestController;
6
use ReflectionMethod;
7
use Zend\Diactoros\ServerRequest;
8
9
class SplashRequestParameterFetcherTest extends \PHPUnit_Framework_TestCase
10
{
11
    public function testSplashRequestParameterFetcher()
12
    {
13
        $method = new ReflectionMethod(TestController::class, 'myAction');
14
        $params = $method->getParameters();
15
16
        $splashRequestFetcher = new SplashRequestParameterFetcher();
17
        //$this->assertFalse($splashRequestFetcher->canHandle($params[0]));
18
        $this->assertTrue($splashRequestFetcher->canHandle($params[2]));
19
20
        $data = $splashRequestFetcher->getFetcherData($params[2]);
21
        $this->assertEquals([
22
            'key' => 'id',
23
            'compulsory' => false,
24
            'default' => null,
25
        ], $data);
26
27
        $dataCompulsory = $splashRequestFetcher->getFetcherData($params[1]);
28
        $this->assertEquals([
29
            'key' => 'compulsory',
30
            'compulsory' => true,
31
        ], $dataCompulsory);
32
33
        $request = new ServerRequest(
34
            [],
35
            [],
36
            'toto/tata',
37
            'GET',
38
            'php://input',
39
            [],
40
            [],
41
            [
42
                'id' => 42,
43
            ]
44
        );
45
        $context = new SplashRequestContext($request);
46
47
        $this->assertSame(42, $splashRequestFetcher->fetchValue($data, $context));
48
    }
49
}
50