Skip to content

Commit 2335c75

Browse files
authored
Move integration tests to phpunit (#387)
* moved integration tests to phpunit * updated integration tests description in CONTRIBUTING.md * added `name` parameter to `patchUser` so the sample file works properly * added `Retrievable` interface to `VolumeType` * added `HasWaiterTrait` to `Compute::Image` * added `Token::validate()` function to check if Identity token is valid --------- Co-authored-by: k0ka <[email protected]>
1 parent 45bd478 commit 2335c75

File tree

156 files changed

+4751
-3124
lines changed

Some content is hidden

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

156 files changed

+4751
-3124
lines changed

.gitattributes

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
/tests export-ignore
55
/.gitattributes export-ignore
66
/.gitignore export-ignore
7-
/.php_cs.dist export-ignore
7+
/.php-cs-fixer.dist.php export-ignore
8+
/.readthedocs.yaml export-ignore
89
/.scrutinizer.yml export-ignore
9-
/.travis.yml export-ignore
10+
/phpunit.sample.xml.dist export-ignore
1011
/phpunit.xml.dist export-ignore

.github/workflows/integration_tests.yml

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,9 @@ jobs:
9696
echo OS_FLAVOR=1
9797
echo OS_DOMAIN_ID=default
9898
} >> "$GITHUB_ENV"
99-
- name: Execute Block Storage v2 tests
99+
- name: Check if Block Storage API v2 must be tested
100100
if: matrix.block_storage_v2 == true
101-
run: php ./tests/integration/run.php -s=BlockStorage -v=v2
102-
- name: Execute Block Storage v3 tests
103-
run: php ./tests/integration/run.php -s=BlockStorage -v=v3
104-
- name: Execute Compute tests
105-
run: php ./tests/integration/run.php -s=Compute
106-
- name: Execute Identity tests
107-
run: php ./tests/integration/run.php -s=Identity
108-
- name: Execute Images tests
109-
run: php ./tests/integration/run.php -s=Images
110-
- name: Execute Networking tests
111-
run: php ./tests/integration/run.php -s=Networking
112-
- name: Execute Object Storage tests
113-
run: php ./tests/integration/run.php -s=ObjectStore
101+
run: echo "OS_BLOCK_STORAGE_V2=1" >> "$GITHUB_ENV"
102+
- name: Execute Integration tests via PhpUnit
103+
run: vendor/bin/phpunit --configuration ./phpunit.sample.xml.dist
114104

.travis.yml

Lines changed: 0 additions & 40 deletions
This file was deleted.

CONTRIBUTING.md

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ The second argument to `setupMockResponse` is an external file, storing a string
185185
We use phpunit, so you run this at the project root:
186186

187187
```bash
188-
phpunit
188+
vendor/bin/phpunit
189189
```
190190

191191
### Integration tests
@@ -203,29 +203,46 @@ service charges from your provider. Although most tests handle their own
203203
teardown procedures, it is always worth manually checking that resources are
204204
deleted after the test suite finishes.
205205

206+
It is recommended to run integration test in a separate OpenStack project, so that you can easily clean up all resources.
207+
206208
We use all of our sample files as live integration tests, achieving the dual aim of reducing code duplication and
207209
ensuring that our samples actually work.
208210

211+
### Setting up dev environment
212+
213+
In order to run integration tests, you need to have a working OpenStack environment.
214+
You can use [DevStack](http://docs.openstack.org/developer/devstack/) to set up a local OpenStack environment.
215+
DevStack will make substantial changes to your system during installation. Only run DevStack on servers or
216+
virtual machines that are dedicated to this purpose.
217+
218+
Installation is pretty straightforward. You can use guide on their [website](http://docs.openstack.org/developer/devstack/).
219+
220+
Here is currently used `local.conf` for DevStack:
221+
222+
```ini
223+
[[local|localrc]]
224+
ADMIN_PASSWORD=secret
225+
DATABASE_PASSWORD=root
226+
RABBIT_PASSWORD=secret
227+
SERVICE_PASSWORD=secret
228+
SWIFT_HASH=1234123412341234
229+
LOGFILE=/tmp/devstack-logs/devstack.log
230+
USE_PYTHON3=True
231+
INSTALL_TEMPEST=False
232+
GIT_BASE=https://github.com
233+
ENABLED_SERVICES+=,-horizon,-dstat,-tempest,s-account,s-container,s-object,s-proxy,s-bak
234+
SWIFT_ENABLE_TEMPURLS=True
235+
SWIFT_TEMPURL_KEY=secretkey
236+
237+
[[post-config|$SWIFT_CONFIG_PROXY_SERVER]]
238+
[filter:versioned_writes]
239+
allow_object_versioning = true
240+
```
241+
209242
### Setting up environment variables
210243

211244
Rename `env_test.sh.dist` as `env_test.sh` and replace values according to your OpenStack instance configuration.
212-
Completed file may look as following.
213-
214-
215-
```bash
216-
#!/usr/bin/env bash
217-
export OS_AUTH_URL="http://1.2.3.4:5000/v3"
218-
export OS_REGION="RegionOne"
219-
export OS_REGION_NAME="RegionOne"
220-
export OS_USER_ID="536068bcb1b946ff8e2f10eff6543f9c"
221-
export OS_USERNAME="admin"
222-
export OS_PASSWORD="2251639ecaea442b"
223-
export OS_PROJECT_ID="b62b3bebf9e84e4eb11aafcd8c58db3f"
224-
export OS_PROJECT_NAME="admin"
225-
export OS_RESIZE_FLAVOR=2 #Must be a valid flavor ID
226-
export OS_FLAVOR=1 #Must be a valid flavor ID
227-
export OS_DOMAIN_ID="default"
228-
```
245+
If you are using DevStack with config file above, the values would be filled automatically.
229246

230247
To export environment variables, run
231248
```bash
@@ -236,23 +253,12 @@ Additionally, integration tests require image called `cirros` exists.
236253

237254
### Running integration tests
238255

239-
You interact with integration tests through a runner script:
256+
We use phpunit, so you run this at the project root:
240257

241258
```bash
242-
php ./tests/integration/run.php [-s=BlockStorage|Compute|Identity|Images|Networking|ObjectStore] [--debug=1|2]
259+
vendor/bin/phpunit --configuration ./phpunit.sample.xml.dist
243260
```
244261

245-
It supports these command-line flags:
246-
247-
| Flag | Description | Example |
248-
| ---- | ----------- | ------- |
249-
| `-s` `--service` | Allows you to refine tests by a particular service. A service corresponds to top-level directories in the `./integration` directory, meaning that `compute` and `identity` are services because they exist as sub-directories there. If omitted, all services are run.|Run compute service: `php ./tests/integration/run.php -s compute` Run all tests: `php ./tests/integration/run.php`|
250-
| `-v` `--version` | Allows you to refine by a particular service version. A version corresponds to the sub-directories inside a service directory, meaning that `v2` is a supported version of `compute` because it exists as a sub-directory inside the `compute` directory. If omitted, all versions are run.|Run v2 Compute tests: `php ./tests/integration/run.php -s compute -v v2` Run all compute tests: `php ./tests/integration/run.php -s compute`|
251-
| `-t` `--test` | Allows you to refine by a particular test. Tests are defined in classes like `integration\OpenStack\Compute\v2`. Each test method manually references a sample file. To refine which tests are run, list the name of the method in this class. If omitted, all tests are run.|Run create server test: `php ./tests/integration/run.php -s compute -v v2 -t createServer` Run all compute v2 tests: `php ./tests/integration/run.php -s compute -v v2`|
252-
| `--debug` |||
253-
| `--help` | A help screen is returned and no tests run | `php ./tests/integration/run.php --help`
254-
255-
256262
## Style guide
257263

258264
We follow [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) for our
@@ -281,14 +287,11 @@ required to adhere to:
281287

282288
### 1. Providing feedback
283289

284-
On of the easiest ways to get readily involved in our project is to let us know
290+
One of the easiest ways to get readily involved in our project is to let us know
285291
about your experiences using our SDK. Feedback like this is incredibly useful
286292
to us, because it allows us to refine and change features based on what our
287-
users want and expect of us. There are a bunch of ways to get in contact! You
288-
can [ping us](https://developer.rackspace.com/support/) via e-mail, talk to us on irc
289-
(#rackspace-dev on freenode), [tweet us](https://twitter.com/rackspace), or
290-
submit an issue on our [bug tracker](/issues). Things you might like to tell us
291-
are:
293+
users want and expect of us. You can submit an issue on our [bug tracker](/issues).
294+
Things you might like to tell us are:
292295

293296
* how easy was it to start using our SDK?
294297
* did it meet your expectations? If not, why not?
@@ -309,8 +312,7 @@ breakthroughs on it so far.
309312
We have three forms of documentation:
310313

311314
* short README documents that briefly introduce a topic
312-
* reference documentation
313-
* user documentation on http://docs.php-opencloud.com that includes
315+
* user documentation on https://php-openstack-sdk.readthedocs.io that includes
314316
getting started guides, installation guides and code samples
315317

316318
If you feel that a certain section could be improved - whether it's to clarify

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"autoload-dev": {
5151
"psr-4": {
5252
"OpenStack\\Integration\\": "tests/integration/",
53+
"OpenStack\\Sample\\": "tests/sample/",
5354
"OpenStack\\Test\\": "tests/unit/"
5455
}
5556
},

doc/services/compute/v2/servers.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ This operation will reset the state of the server.
229229
Reboot server
230230
-------------
231231

232-
This operation will reboot a server. Please be aware that you must specify whether you want to initiate a HARD or
233-
SOFT reboot (you specify this as a string argument).
232+
This operation will reboot a server. You can specify HARD reboot by passing argument Enum::REBOOT_HARD to the function.
233+
Otherwise, the default is a SOFT reboot.
234234

235235
.. sample:: Compute/v2/servers/reboot_server.php
236236
.. refdoc:: OpenStack/Compute/v2/Models/Server.html#method_reboot

env_test.sh.dist

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#!/usr/bin/env bash
2-
export OS_AUTH_URL=""
3-
export OS_REGION=""
4-
export OS_REGION_NAME=""
5-
export OS_USER_ID=""
6-
export OS_USERNAME=""
7-
export OS_PASSWORD=""
8-
export OS_PROJECT_ID=""
9-
export OS_PROJECT_NAME=""
10-
export OS_RESIZE_FLAVOR=""
11-
export OS_FLAVOR=""
2+
3+
export OS_AUTH_URL="$(grep -oP -m 1 "(?<=auth_url: )(.*)\$" /etc/openstack/clouds.yaml)/v3"
4+
export OS_REGION="RegionOne"
5+
export OS_REGION_NAME="RegionOne"
6+
export OS_USER_ID=$(openstack --os-cloud=devstack-admin user show admin -f value -c id)
7+
export OS_USERNAME="admin"
8+
export OS_PASSWORD="secret"
9+
export OS_PROJECT_ID=$(openstack --os-cloud=devstack-admin project show admin -f value -c id)
10+
export OS_PROJECT_NAME="admin"
11+
export OS_RESIZE_FLAVOR="c1"
12+
export OS_FLAVOR=1
1213
export OS_DOMAIN_ID="default"

phpunit.sample.xml.dist

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
5+
bootstrap="./vendor/autoload.php"
6+
colors="true"
7+
beStrictAboutOutputDuringTests="true"
8+
stopOnError="true"
9+
stopOnFailure="true"
10+
printerClass="\PHPUnit\Util\TestDox\CliTestDoxPrinter"
11+
verbose="true"
12+
>
13+
<testsuites>
14+
<testsuite name="Sample">
15+
<directory>tests/sample</directory>
16+
</testsuite>
17+
</testsuites>
18+
<php>
19+
<ini name="error_reporting" value=""/>
20+
<ini name="display_errors" value="On"/>
21+
<ini name="display_startup_errors" value="On"/>
22+
</php>
23+
</phpunit>

phpunit.xml.dist

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit bootstrap="./vendor/autoload.php" colors="true" beStrictAboutOutputDuringTests="true">
3-
<logging>
4-
<log type="coverage-clover" target="build/logs/clover.xml"/>
5-
</logging>
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
5+
bootstrap="./vendor/autoload.php"
6+
colors="true"
7+
beStrictAboutOutputDuringTests="true"
8+
>
69
<testsuites>
7-
<testsuite name="OpenStack">
10+
<testsuite name="Unit">
811
<directory>tests/unit</directory>
912
</testsuite>
1013
</testsuites>
@@ -13,14 +16,4 @@
1316
<ini name="display_errors" value="On"/>
1417
<ini name="display_startup_errors" value="On"/>
1518
</php>
16-
<filter>
17-
<whitelist>
18-
<directory suffix=".php">./src</directory>
19-
<exclude>
20-
<directory suffix="Interface.php">./src</directory>
21-
<directory suffix="Api.php">./src</directory>
22-
<directory suffix="Params.php">./src</directory>
23-
</exclude>
24-
</whitelist>
25-
</filter>
2619
</phpunit>

samples/BlockStorage/v3/snapshots/list.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
$snapshots = $service->listSnapshots();
1515

1616
foreach ($snapshots as $snapshot) {
17-
/** @var $snapshot \OpenStack\BlockStorage\v2\Models\Snapshot */
17+
/** @var \OpenStack\BlockStorage\v2\Models\Snapshot $snapshot */
1818
}

samples/BlockStorage/v3/snapshots/list_sorted.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
$snapshots = $service->listSnapshots(false, ['sortKey' => '{sortKey}', 'sortDir' => '{sortDir}']);
1515

1616
foreach ($snapshots as $snapshot) {
17-
/** @var $snapshot \OpenStack\BlockStorage\v2\Models\Snapshot */
17+
/** @var \OpenStack\BlockStorage\v2\Models\Snapshot $snapshot */
1818
}

samples/BlockStorage/v3/volume_types/list.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
$volumeTypes = $service->listVolumeTypes();
1515

1616
foreach ($volumeTypes as $volumeType) {
17-
/** @var $volumeType \OpenStack\BlockStorage\v2\VolumeType */
17+
/** @var \OpenStack\BlockStorage\v2\Models\VolumeType $volumeType */
1818
}

samples/BlockStorage/v3/volumes/list.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
$volumes = $service->listVolumes();
1515

1616
foreach ($volumes as $volume) {
17-
/** @var $volume \OpenStack\BlockStorage\v2\Models\Volume */
17+
/** @var \OpenStack\BlockStorage\v2\Models\Volume $volume */
1818
}

samples/BlockStorage/v3/volumes/update.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
'authUrl' => '{authUrl}',
77
'region' => '{region}',
88
'user' => ['id' => '{userId}', 'password' => '{password}'],
9-
'scope' => ['project' => ['id' => '{projectId}']]
9+
'scope' => ['project' => ['id' => '{projectId}']],
1010
]);
1111

1212
$service = $openstack->blockStorageV3();
1313

1414
$volume = $service->getVolume('{volumeId}');
1515

16-
$volume->name = '{newName}';
16+
$volume->name = '{newName}';
1717
$volume->description = '{newDescription}';
1818

1919
$volume->update();

samples/Compute/v2/flavors/list_flavors.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@
1717
$flavors = $compute->listFlavors();
1818

1919
foreach ($flavors as $flavor) {
20+
/** @var \OpenStack\Compute\v2\Models\Flavor $flavor */
2021
}

samples/Compute/v2/hypervisors/get_hypervisors_statistics.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,4 @@
1616

1717
$compute = $openstack->computeV2(['region' => '{region}']);
1818

19-
/** @var HypervisorStatistic $hypervisorStatistics */
2019
$hypervisorStatistics = $compute->getHypervisorStatistics();

samples/Compute/v2/hypervisors/list_hypervisors.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
use OpenStack\Compute\v2\Models\Hypervisor;
4-
53
require 'vendor/autoload.php';
64

75
$openstack = new OpenStack\OpenStack([
@@ -19,5 +17,5 @@
1917
$hypervisors = $compute->listHypervisors();
2018

2119
foreach ($hypervisors as $hypervisor) {
22-
/**@var Hypervisor $hypervisor*/
20+
/** @var \OpenStack\Compute\v2\Models\Hypervisor $hypervisor */
2321
}

samples/Compute/v2/images/delete_image_metadata_item.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616

1717
$image = $compute->getImage(['id' => '{imageId}']);
1818

19-
$image->deleteMetadataItem('key');
19+
$image->deleteMetadataItem('{key}');

samples/Compute/v2/images/list_images.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@
1717
$images = $compute->listImages(['status' => 'ACTIVE']);
1818

1919
foreach ($images as $image) {
20+
/** @var \OpenStack\Compute\v2\Models\Image $image */
2021
}

0 commit comments

Comments
 (0)