FragmentTest::testSortFields()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 9
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 15
rs 9.9666
1
<?php
2
3
namespace Tests\Fnash\GraphQL;
4
5
use Fnash\GraphQL\Fragment;
6
use Fnash\GraphQL\Query;
7
use PHPUnit\Framework\TestCase;
8
9
class FragmentTest extends TestCase
10
{
11
    /**
12
     * Tests adding fields and args using constructor parameters or method call.
13
     */
14
    public function testAddFields()
15
    {
16
        $fragment1 = Fragment::create('articleFragment', 'article', [
17
           'id',
18
           'title',
19
           'image' => Query::create()->fields([
20
                'width',
21
                'height',
22
                'filename',
23
                'size',
24
           ]),
25
        ]);
26
27
        $fragment2 = Fragment::create('articleFragment', 'article')->fields([
28
           'id',
29
           'title',
30
           'image' => Query::create()->fields([
31
                'width',
32
                'height',
33
                'filename',
34
                'size',
35
           ]),
36
        ]);
37
38
        $expected =
39
            'fragment articleFragment on article {
40
  id
41
  image {
42
    filename
43
    height
44
    size
45
    width
46
  }
47
  title
48
}
49
';
50
        $this->assertEquals($expected, (string) $fragment1);
51
        $this->assertEquals($expected, (string) $fragment2);
52
    }
53
54
    /**
55
     * Tests the order of fields.
56
     */
57
    public function testSortFields()
58
    {
59
        $fragment1 = Fragment::create('articleFragment', 'article', [
60
            'id',
61
            'title',
62
            'image',
63
        ]);
64
65
        $fragment2 = Fragment::create('articleFragment', 'article')->fields([
66
            'title',
67
            'image',
68
            'id',
69
        ]);
70
71
        $this->assertEquals((string) $fragment1, (string) $fragment2);
72
    }
73
}
74