1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Kreta package. |
5
|
|
|
* |
6
|
|
|
* (c) Beñat Espiña <[email protected]> |
7
|
|
|
* (c) Gorka Laucirica <[email protected]> |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
10
|
|
|
* file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
declare(strict_types=1); |
14
|
|
|
|
15
|
|
|
namespace Kreta\TaskManager\Tests\Integration\GraphQl\Query\Project; |
16
|
|
|
|
17
|
|
|
use Lakion\ApiTestCase\JsonApiTestCase; |
18
|
|
|
|
19
|
|
View Code Duplication |
class ProjectsResolverTest extends JsonApiTestCase |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
public function testProjectsResolver() |
22
|
|
|
{ |
23
|
|
|
$this->projectsResolver('access-token-1', [], '/projects'); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testProjectsFilteredByNameResolver() |
27
|
|
|
{ |
28
|
|
|
$this->projectsResolver('access-token-1', ['name' => '2'], '/projects_filtered_by_name'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testProjectsFilteredByOrganizationResolver() |
32
|
|
|
{ |
33
|
|
|
$this->projectsResolver( |
34
|
|
|
'access-token-1', |
35
|
|
|
[ |
36
|
|
|
'organizationId' => '71298d2c-0ff4-11e7-93ae-92361f002671', |
37
|
|
|
], |
38
|
|
|
'/projects_filtered_by_organization' |
39
|
|
|
); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testProjectsWithAfter3AndFirst2() |
43
|
|
|
{ |
44
|
|
|
$this->projectsResolver('access-token-1', ['after' => '3', 'first' => '2'], '/projects_paginated'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testProjectsWithOtherUserResolver() |
48
|
|
|
{ |
49
|
|
|
$this->projectsResolver('access-token-2', [], '/projects_of_user2'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
private function projectsResolver($token, $projectConnectionInput, $jsonResult) |
53
|
|
|
{ |
54
|
|
|
$this->client->request('POST', '/?access_token=' . $token, [ |
55
|
|
|
'query' => <<<EOF |
56
|
|
|
query ProjectsQueryRequest(\$projectConnectionInput: ProjectConnectionInput!) { |
57
|
|
|
projects(projectConnectionInput: \$projectConnectionInput) { |
58
|
|
|
totalCount, |
59
|
|
|
edges { |
60
|
|
|
node { |
61
|
|
|
id, |
62
|
|
|
name, |
63
|
|
|
slug, |
64
|
|
|
organization { |
65
|
|
|
id, |
66
|
|
|
name, |
67
|
|
|
slug, |
68
|
|
|
owners { |
69
|
|
|
id |
70
|
|
|
}, |
71
|
|
|
organization_members { |
72
|
|
|
id |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
EOF |
80
|
|
|
, 'variables' => ['projectConnectionInput' => $projectConnectionInput], |
81
|
|
|
]); |
82
|
|
|
|
83
|
|
|
$response = $this->client->getResponse(); |
84
|
|
|
|
85
|
|
|
$this->assertResponse($response, 'graphql/query/project' . $jsonResult); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.