Passed
Push — master ( e0b449...e45870 )
by Fayez
11:16
created

MutationTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 56
c 1
b 0
f 1
dl 0
loc 84
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testMutation() 0 26 1
A testOperationName() 0 50 1
1
<?php
2
3
namespace Tests\Fnash\GraphQL;
4
5
use Fnash\GraphQL\Mutation;
6
use Fnash\GraphQL\Query;
7
use PHPUnit\Framework\TestCase;
8
9
class MutationTest extends TestCase
10
{
11
    public function testMutation()
12
    {
13
        $mutation = Mutation::create('createReview')
14
            ->operationName('CreateReviewForEpisode')
15
            ->variables([
16
                '$ep' => 'Episode!',
17
                '$review' => 'ReviewInput!',
18
            ])
19
            ->arguments([
20
                'episode' => '$ep',
21
                'review' => '$review',
22
            ])
23
            ->fields([
24
                'stars',
25
                'commentary',
26
            ]);
27
28
        $expected =
29
'mutation CreateReviewForEpisode($ep: Episode!, $review: ReviewInput!) {
30
  createReview(episode: $ep, review: $review) {
31
    commentary
32
    stars
33
  }
34
}
35
';
36
        $this->assertEquals($expected, (string) $mutation);
37
    }
38
39
40
    /**
41
     * Tests operation name generation and printing.
42
     */
43
    public function testOperationName()
44
    {
45
        // simple mutation without variables nor operation name
46
        $mutation = Mutation::create('createReview')
47
            ->arguments([
48
                'episode' => 123,
49
                'review' => 'great review as string',
50
            ])
51
            ->fields([
52
                'stars',
53
                'commentary',
54
            ]);
55
56
        $expected =
57
'mutation {
58
  createReview(episode: 123, review: "great review as string") {
59
    commentary
60
    stars
61
  }
62
}
63
';
64
65
        $this->assertEquals($expected, (string) $mutation);
66
67
68
        // mutation with variables but no operation name
69
        $mutation = Mutation::create('createReview')
70
            ->variables([
71
                '$ep' => 'Episode!',
72
                '$review' => 'ReviewInput!',
73
            ])
74
            ->arguments([
75
                'episode' => '$ep',
76
                'review' => '$review',
77
            ])
78
            ->fields([
79
                'stars',
80
                'commentary',
81
            ]);
82
83
        $expected =
84
'mutation mutation_4db26a2e56d1146f7c7715edf0d1d5d55eeb261c($ep: Episode!, $review: ReviewInput!) {
85
  createReview(episode: $ep, review: $review) {
86
    commentary
87
    stars
88
  }
89
}
90
';
91
92
        $this->assertEquals($expected, (string) $mutation);
93
    }
94
}
95