Skip to content

Commit 42b3063

Browse files
authored
Refactored Management API tests and various improvements (#25)
Highlights: * Block installation of the latest vimeo/psalm. vimeo/psalm#1016 * Introducing new API and HTTP clients for testing. * Updated Management API tests to use the new test API- and HTTP clients. * Explode entity CRUD operation trait and interface to smaller components per operation. * Added missing organization property to Company entity. * Added more details about the actual behavior of the Company membership API. * Introducing new base class and interface for developer- and company entity. * Refactored basic and Management API tests. * Bump minimum version of php-http/client-common to >=1.8.1. 1.8.0 contains a regression bug: php-http/client-common#112 * Add new required patch to php-http/client-common. php-http/client-common#113 * Disable process timeout to prevent failing test runs caused by PHPUnit executed via a Composer command. * Removed useless PHP nightly builds from testing matrix. * Added test to getDeveloperByApp. * Introducing new base exception interface for our client. * Introducing API client specific RuntimeException class. * Throw more meaningful exceptions when an entity property has an incorrect value. * Be more type-strict by replacing array arguments on data object's setters with type strict variable-length arguments. * Fix implementation of getProperties(). (BC breaking change.)
1 parent 564ea5a commit 42b3063

File tree

175 files changed

+6047
-2615
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

175 files changed

+6047
-2615
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@ addons:
99
php:
1010
- 7.1
1111
- 7.2
12-
- nightly
1312

1413
matrix:
1514
fast_finish: true
16-
allow_failures:
17-
- php: nightly
1815

1916
cache:
2017
directories:
@@ -27,6 +24,9 @@ notifications:
2724
env:
2825
global:
2926
- COMPOSER_OPTIONS="--no-suggest --no-interaction"
27+
# To prevent failing test runs caused by
28+
# "The process "phpunit" exceeded the timeout of 300 seconds.
29+
- COMPOSER_PROCESS_TIMEOUT=0
3030
matrix:
3131
- DEPENDENCIES="--prefer-lowest"
3232
- DEPENDENCIES=""

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ Testing of new changes does not require Apigee Edge connection. By default, unit
134134
tests with a real Apigee Edge instance you have to specify the following environment variables (without brackets):
135135

136136
```shell
137+
APIGEE_EDGE_PHP_CLIENT_API_CLIENT=\Apigee\Edge\Tests\Test\FileSystemMockClient
137138
APIGEE_EDGE_PHP_CLIENT_HTTP_CLIENT=\Http\Adapter\Guzzle6\Client
138139
APIGEE_EDGE_PHP_CLIENT_BASIC_AUTH_USER=[[email protected]]
139140
APIGEE_EDGE_PHP_CLIENT_BASIC_AUTH_PASSWORD=[PASSWORD]

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"fightbulc/moment": "^1.26",
2020
"league/period": "^3.4",
2121
"php-http/cache-plugin": "^1.4",
22-
"php-http/client-common": "^1.6",
22+
"php-http/client-common": "^1.8.1",
2323
"php-http/client-implementation": "^1.0",
2424
"php-http/discovery": "^1.0",
2525
"php-http/httplug": "^1.0",
@@ -46,13 +46,14 @@
4646
"phpmetrics/phpmetrics": "^2.3",
4747
"phpunit/phpunit": "^6.4.0",
4848
"sebastian/comparator": "^2.1",
49+
"symfony/cache": "~3.4|~4.0",
4950
"vimeo/psalm": "^2.0.0"
5051
},
5152
"conflict": {
5253
"guzzlehttp/guzzle": "<6.1.0",
5354
"guzzlehttp/psr7": "<1.4.1",
5455
"phpdocumentor/type-resolver": "<0.2.1",
55-
"php-http/client-common": ">1.7"
56+
"vimeo/psalm": ">2.0.13"
5657
},
5758
"autoload": {
5859
"psr-4": {
@@ -86,7 +87,7 @@
8687
},
8788
"patches": {
8889
"php-http/client-common": {
89-
"Only add path prefix if the path does not contain it already #103": "https://patch-diff.githubusercontent.com/raw/php-http/client-common/pull/103.diff"
90+
"Path prefix must be present #113": "https://github.com/php-http/client-common/pull/113.diff"
9091
}
9192
}
9293
}

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
printerClass="LimeDeck\Testing\Printer"
2525
verbose="true">
2626
<testsuites>
27-
<testsuite name="All Apigee Edge PHP SDK Tests">
27+
<testsuite name="All Apigee Edge PHP API Client Tests">
2828
<directory>tests/</directory>
2929
</testsuite>
3030
</testsuites>

src/Api/Management/Controller/AppControllerInterface.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,24 @@
3131
interface AppControllerInterface extends PaginatedEntityControllerInterface, EntityControllerInterface
3232
{
3333
/**
34-
* String that should be sent to the API to change the status of a credential to approved.
34+
* Type of a developer app.
35+
*/
36+
public const APP_TYPE_DEVELOPER = 'developer';
37+
38+
/**
39+
* Type of a company app.
40+
*/
41+
public const APP_TYPE_COMPANY = 'company';
42+
43+
/**
44+
* String that should be sent to the API to change the status of a
45+
* credential to approved.
3546
*/
3647
public const STATUS_APPROVE = 'approve';
3748

3849
/**
39-
* String that should be sent to the API to change the status of a credential to revoked.
50+
* String that should be sent to the API to change the status of a
51+
* credential to revoked.
4052
*/
4153
public const STATUS_REVOKE = 'revoke';
4254

src/Api/Management/Controller/CompanyMembersControllerInterface.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ public function getMembers(): CompanyMembership;
3838
/**
3939
* Set (add/update/remove) members of a company.
4040
*
41-
* You have to pass the complete list of developers otherwise you remove previously added developers from
42-
* a company.
41+
* Warning! If you pass en empty membership object you remove all developers
42+
* from the company.
43+
*
44+
* The return array only contains the changes, it does not contain all
45+
* members. Use getMembers() to retrieve it.
4346
*
4447
* @param \Apigee\Edge\Api\Management\Structure\CompanyMembership $members
4548
* Array of developers with their optional roles in the company.

src/Api/Management/Controller/DeveloperController.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,7 @@ public function getEntities(
9999
}
100100

101101
/**
102-
* Returns the API endpoint that the controller communicates with.
103-
*
104-
* In case of an entity that belongs to an organisation it should return organization/[orgName]/[endpoint].
105-
*
106-
* @return UriInterface
102+
* @inheritdoc
107103
*/
108104
protected function getBaseEndpointUri(): UriInterface
109105
{

src/Api/Management/Entity/ApiProduct.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function getProxies(): array
9595
/**
9696
* @inheritdoc
9797
*/
98-
public function setProxies(array $proxies): void
98+
public function setProxies(string ...$proxies): void
9999
{
100100
$this->proxies = $proxies;
101101
}
@@ -175,7 +175,7 @@ public function getApiResources(): array
175175
/**
176176
* @inheritdoc
177177
*/
178-
public function setApiResources(array $apiResources): void
178+
public function setApiResources(string ...$apiResources): void
179179
{
180180
$this->apiResources = $apiResources;
181181
}

src/Api/Management/Entity/ApiProductInterface.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ interface ApiProductInterface extends
5858
public function getProxies(): array;
5959

6060
/**
61-
* @param string[] $proxy
61+
* @param string ...$proxy
6262
*/
63-
public function setProxies(array $proxy): void;
63+
public function setProxies(string ...$proxy): void;
6464

6565
/**
6666
* @return string|null
@@ -108,7 +108,7 @@ public function setApprovalType(string $approvalType): void;
108108
public function getApiResources(): array;
109109

110110
/**
111-
* @param string[] $apiResources
111+
* @param string ...$apiResources
112112
*/
113-
public function setApiResources(array $apiResources): void;
113+
public function setApiResources(string ...$apiResources): void;
114114
}

src/Api/Management/Entity/App.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,31 +186,32 @@ public function getCredentials(): array
186186
}
187187

188188
/**
189-
* Set credentials from an Edge API response.
189+
* Set credentials from an Apigee Edge API response.
190190
*
191191
* Credentials, included in app, can not be changed by modifying them on the entity level.
192192
*
193-
* @param \Apigee\Edge\Api\Management\Entity\AppCredentialInterface[] $credentials
193+
* @param \Apigee\Edge\Api\Management\Entity\AppCredentialInterface ...$credentials
194194
*
195195
* @internal
196196
*/
197-
public function setCredentials(array $credentials): void
197+
public function setCredentials(AppCredentialInterface ...$credentials): void
198198
{
199199
$this->credentials = $credentials;
200200
}
201201

202202
/**
203203
* Set OAuth scopes from an Edge API response.
204204
*
205-
* Scopes of an app should not be changed on the entity level. You should modify them by using the app credential
205+
* Scopes of an app should not be changed on the entity level.
206+
* You should modify them by using the app credential
206207
* controllers.
207208
*
208-
* @param string[] $scopes
209+
* @param string ...$scopes
209210
*
210211
* @internal
211212
*/
212-
public function setScopes(array $scopes): void
213+
public function setScopes(string ...$scopes): void
213214
{
214-
$this->privateSetScopes($scopes);
215+
$this->privateSetScopes(...$scopes);
215216
}
216217
}

src/Api/Management/Entity/AppCredential.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Apigee\Edge\Entity\Property\ScopesPropertyAwareTrait;
2424
use Apigee\Edge\Entity\Property\StatusPropertyAwareTrait;
2525
use Apigee\Edge\Structure\AttributesProperty;
26+
use Apigee\Edge\Structure\CredentialProductInterface;
2627

2728
/**
2829
* Class AppCredential.
@@ -92,11 +93,11 @@ public function getApiProducts(): array
9293
*
9394
* Included API products in an app credential can not be changed by modifying this property's value.
9495
*
95-
* @param \Apigee\Edge\Structure\CredentialProductInterface[] $apiProducts
96+
* @param \Apigee\Edge\Structure\CredentialProductInterface ...$apiProducts
9697
*
9798
* @internal
9899
*/
99-
public function setApiProducts(array $apiProducts): void
100+
public function setApiProducts(CredentialProductInterface ...$apiProducts): void
100101
{
101102
$this->apiProducts = $apiProducts;
102103
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2018 Google LLC
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
namespace Apigee\Edge\Api\Management\Entity;
20+
21+
use Apigee\Edge\Entity\CommonEntityPropertiesAwareTrait;
22+
use Apigee\Edge\Entity\Entity;
23+
use Apigee\Edge\Entity\Property\AppsPropertyAwareTrait;
24+
use Apigee\Edge\Entity\Property\AttributesPropertyAwareTrait;
25+
use Apigee\Edge\Entity\Property\StatusPropertyAwareTrait;
26+
27+
/**
28+
* Base class for developer- and company entities.
29+
*/
30+
abstract class AppOwner extends Entity implements AppOwnerInterface
31+
{
32+
use AttributesPropertyAwareTrait;
33+
use AppsPropertyAwareTrait;
34+
use CommonEntityPropertiesAwareTrait;
35+
use StatusPropertyAwareTrait;
36+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2018 Google LLC
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
namespace Apigee\Edge\Api\Management\Entity;
20+
21+
use Apigee\Edge\Entity\CommonEntityPropertiesInterface;
22+
use Apigee\Edge\Entity\EntityInterface;
23+
use Apigee\Edge\Entity\Property\AppsPropertyInterface;
24+
use Apigee\Edge\Entity\Property\AttributesPropertyInterface;
25+
use Apigee\Edge\Entity\Property\StatusPropertyInterface;
26+
27+
/**
28+
* Interface AppOwnerInterface.
29+
*/
30+
interface AppOwnerInterface extends EntityInterface,
31+
AttributesPropertyInterface,
32+
AppsPropertyInterface,
33+
CommonEntityPropertiesInterface,
34+
StatusPropertyInterface
35+
{
36+
public const STATUS_ACTIVE = 'active';
37+
38+
public const STATUS_INACTIVE = 'inactive';
39+
}

src/Api/Management/Entity/Company.php

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,28 @@
1818

1919
namespace Apigee\Edge\Api\Management\Entity;
2020

21-
use Apigee\Edge\Entity\CommonEntityPropertiesAwareTrait;
22-
use Apigee\Edge\Entity\Entity;
23-
use Apigee\Edge\Entity\Property\AppsPropertyAwareTrait;
24-
use Apigee\Edge\Entity\Property\AttributesPropertyAwareTrait;
2521
use Apigee\Edge\Entity\Property\DisplayNamePropertyAwareTrait;
2622
use Apigee\Edge\Entity\Property\NamePropertyAwareTrait;
27-
use Apigee\Edge\Entity\Property\StatusPropertyAwareTrait;
2823
use Apigee\Edge\Structure\AttributesProperty;
2924

3025
/**
3126
* Describes a Company entity.
3227
*/
33-
class Company extends Entity implements CompanyInterface
28+
class Company extends AppOwner implements CompanyInterface
3429
{
35-
use AttributesPropertyAwareTrait;
36-
use AppsPropertyAwareTrait;
37-
use CommonEntityPropertiesAwareTrait;
3830
use DisplayNamePropertyAwareTrait;
3931
use NamePropertyAwareTrait;
40-
use StatusPropertyAwareTrait;
32+
33+
/**
34+
* It is organization and not organizationName in the API response.
35+
*
36+
* This is the reason why it does not implement
37+
* OrganizationNamePropertyInterface. We also id not created a name
38+
* converter just to hide this small inconsistency.
39+
*
40+
* @var string|null
41+
*/
42+
protected $organization;
4143

4244
/**
4345
* Company constructor.
@@ -49,4 +51,20 @@ public function __construct(array $values = [])
4951
$this->attributes = new AttributesProperty();
5052
parent::__construct($values);
5153
}
54+
55+
/**
56+
* @inheritdoc
57+
*/
58+
public function setOrganization(string $organization): void
59+
{
60+
$this->organization = $organization;
61+
}
62+
63+
/**
64+
* @inheritdoc
65+
*/
66+
public function getOrganization(): ?string
67+
{
68+
return $this->organization;
69+
}
5270
}

0 commit comments

Comments
 (0)