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; |
16
|
|
|
|
17
|
|
|
use Lakion\ApiTestCase\JsonApiTestCase; |
18
|
|
|
|
19
|
|
View Code Duplication |
class OrganizationMemberResolverTest extends JsonApiTestCase |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
public function testNonExistOrganizationResolver() |
22
|
|
|
{ |
23
|
|
|
$this->organizationMemberResolver( |
24
|
|
|
'access-token-1', |
25
|
|
|
'non-exist-organization-id', |
26
|
|
|
'a38f8ef4-400b-4229-a5ff-712ff5f72b27', |
27
|
|
|
'/nonexistent_organization_by_organization_member_id' |
28
|
|
|
); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testUnauthorizedOrganizationResolver() |
32
|
|
|
{ |
33
|
|
|
$this->organizationMemberResolver( |
34
|
|
|
'access-token-2', |
35
|
|
|
'71298d2c-0ff4-11e7-93ae-92361f002671', |
36
|
|
|
'a38f8ef4-400b-4229-a5ff-712ff5f72b27', |
37
|
|
|
'/unauthorized_organization_by_organization_member_id' |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testNonExistOrganizationMemberResolver() |
42
|
|
|
{ |
43
|
|
|
$this->organizationMemberResolver( |
44
|
|
|
'access-token-1', |
45
|
|
|
'71298d2c-0ff4-11e7-93ae-92361f002671', |
46
|
|
|
'non-exist-organization-member-id', |
47
|
|
|
'/nonexistent_organization_member_by_id' |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testOrganizationMemberResolver() |
52
|
|
|
{ |
53
|
|
|
$this->organizationMemberResolver( |
54
|
|
|
'access-token-1', |
55
|
|
|
'71298d2c-0ff4-11e7-93ae-92361f002671', |
56
|
|
|
'a38f8ef4-400b-4229-a5ff-712ff5f72b27', |
57
|
|
|
'/organization_member' |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
private function organizationMemberResolver($token, $organizationId, $value, $jsonResult) |
62
|
|
|
{ |
63
|
|
|
$this->client->request('POST', '/?access_token=' . $token, [ |
64
|
|
|
'query' => <<<EOF |
65
|
|
|
query MemberQueryRequest(\$organizationId: ID!, \$organizationMemberId: ID!) { |
66
|
|
|
organizationMember(organizationId: \$organizationId, organizationMemberId: \$organizationMemberId) { |
67
|
|
|
id, |
68
|
|
|
organization { |
69
|
|
|
id, |
70
|
|
|
name |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
EOF |
75
|
|
|
, 'variables' => [ |
76
|
|
|
'organizationId' => $organizationId, |
77
|
|
|
'organizationMemberId' => $value, |
78
|
|
|
], |
79
|
|
|
]); |
80
|
|
|
|
81
|
|
|
$response = $this->client->getResponse(); |
82
|
|
|
|
83
|
|
|
$this->assertResponse($response, 'graphql/query/organization' . $jsonResult); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
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.