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

SplashRequestParameterFetcherTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 1
c 3
b 0
f 0
lcom 1
cbo 4
dl 0
loc 41
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B testSplashRequestParameterFetcher() 0 38 1
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