Completed
Push — master ( 118ce9...9e4cdb )
by Alexandr
02:51
created

InputParseTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 7
dl 0
loc 66
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B testDateInput() 0 29 3
B queries() 0 25 1
1
<?php
2
3
namespace Youshido\Tests\Schema;
4
5
use Youshido\GraphQL\Execution\Processor;
6
use Youshido\GraphQL\Schema\Schema;
7
use Youshido\GraphQL\Type\Object\ObjectType;
8
use Youshido\GraphQL\Type\Scalar\DateTimeType;
9
use Youshido\GraphQL\Type\Scalar\DateTimeTzType;
10
use Youshido\GraphQL\Type\Scalar\StringType;
11
12
class InputParseTest extends \PHPUnit_Framework_TestCase
13
{
14
15
    /**
16
     * @dataProvider queries
17
     *
18
     * @param $query
19
     * @param $expected
20
     */
21
    public function testDateInput($query, $expected)
22
    {
23
        $schema = new Schema([
24
            'query' => new ObjectType([
25
                'name'   => 'RootQuery',
26
                'fields' => [
27
                    'stringQuery' => [
28
                        'type'    => new StringType(),
29
                        'args'    => [
30
                            'from'   => new DateTimeType(),
31
                            'fromtz' => new DateTimeTzType(),
32
                        ],
33
                        'resolve' => function ($source, $args) {
34
                            return sprintf('Result with %s date and %s tz',
35
                                empty($args['from']) ? 'default' : $args['from'],
36
                                empty($args['fromtz']) ? 'default' : $args['fromtz']
37
                            );
38
                        },
39
                    ],
40
                ]
41
            ])
42
        ]);
43
44
        $processor = new Processor($schema);
45
        $processor->processPayload($query);
46
        $result = $processor->getResponseData();
47
48
        $this->assertEquals($expected, $result);
49
    }
50
51
    public function queries()
52
    {
53
        return [
54
            [
55
                '{
56
                  stringQuery(fromtz: "Mon, 14 Nov 2016 04:48:13 +0000")
57
                }',
58
                [
59
                    'data' => [
60
                        'stringQuery' => 'Result with default date and Mon, 14 Nov 2016 04:48:13 +0000 tz'
61
                    ],
62
                ]
63
            ],
64
            [
65
                '{
66
                  stringQuery(from: "2016-10-30 06:10:22")
67
                }',
68
                [
69
                    'data' => [
70
                        'stringQuery' => 'Result with 2016-10-30 06:10:22 date and default tz'
71
                    ],
72
                ]
73
            ],
74
        ];
75
    }
76
77
}