Skip to content

Commit 3f84692

Browse files
authored
Unit test (#360)
* fix tests for new Guzzle * unit tests workflow
1 parent 2a534ca commit 3f84692

File tree

8 files changed

+73
-10
lines changed

8 files changed

+73
-10
lines changed

.github/workflows/unit_tests.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Run Unit Tests
2+
on:
3+
push:
4+
pull_request:
5+
jobs:
6+
tests:
7+
runs-on: ubuntu-22.04
8+
if: "!contains(github.event.head_commit.message, 'skip ci') && !contains(github.event.head_commit.message, 'ci skip')"
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
php: [ 7.2, 7.3, 7.4, 8.0, 8.1 ]
13+
name: "php-${{ matrix.php }}"
14+
steps:
15+
- uses: actions/checkout@v2
16+
- name: get cache directory
17+
id: composer-cache
18+
run: |
19+
echo "::set-output name=dir::$(composer config cache-files-dir)"
20+
- uses: actions/cache@v2
21+
with:
22+
path: |
23+
~/.php_cs.cache
24+
${{ steps.composer-cache.outputs.dir }}
25+
key: ${{ runner.os }}-cache-${{ matrix.php }}-${{ hashFiles('**.composer.lock') }}
26+
- uses: shivammathur/setup-php@v2
27+
with:
28+
php-version: ${{ matrix.php }}
29+
extensions: curl
30+
tools: composer:v2
31+
coverage: none
32+
- run: composer install --prefer-dist --no-interaction --no-progress
33+
- run: vendor/bin/parallel-lint --exclude vendor .
34+
- name: execute unit tests
35+
run: vendor/bin/phpunit --configuration phpunit.xml.dist
36+

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ coverage/
44
vendor/
55
*.pyc
66
phpunit.xml
7+
.phpunit.result.cache
78
coverage.xml
89
composer.lock
910
env_test.sh

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
"psr/log": "^1.0",
4444
"php-coveralls/php-coveralls": "^2.0",
4545
"friendsofphp/php-cs-fixer": "^2.18",
46-
"php-parallel-lint/php-parallel-lint": "^1.2"
46+
"php-parallel-lint/php-parallel-lint": "^1.2",
47+
"phpspec/prophecy": "^1.17"
4748
},
4849
"extra": {
4950
"branch-alias": {

samples/images/v2/images/upload_binary_data.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@
1212
$service = $openstack->imagesV2();
1313

1414
$image = $service->getImage('{imageId}');
15-
$stream = \GuzzleHttp\Psr7\stream_for(fopen('{fileName}', 'r'));
15+
16+
$stream = function_exists('\GuzzleHttp\Psr7\stream_for')
17+
? \GuzzleHttp\Psr7\stream_for(fopen('{fileName}', 'r'))
18+
: \GuzzleHttp\Psr7\Utils::streamFor(fopen('{fileName}', 'r'));
19+
1620
$image->uploadData($stream);

tests/unit/Common/Resource/OperatorResourceTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ public function setUp(): void
2828

2929
public function test_it_retrieves_base_http_url()
3030
{
31-
$returnedUri = \GuzzleHttp\Psr7\uri_for('http://foo.com');
31+
$returnedUri = function_exists('\GuzzleHttp\Psr7\uri_for')
32+
? \GuzzleHttp\Psr7\uri_for('http://foo.com')
33+
: \GuzzleHttp\Psr7\Utils::uriFor('http://foo.com');
3234
$this->client->getConfig('base_uri')->shouldBeCalled()->willReturn($returnedUri);
3335

3436
$uri = $this->resource->testBaseUri();

tests/unit/Images/v2/Models/ImageTest.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ public function setUp(): void
3030

3131
public function test_it_retrieves()
3232
{
33-
$this->client->getConfig('base_uri')->shouldBeCalled()->willReturn(\GuzzleHttp\Psr7\uri_for(''));
33+
$returnedUri = function_exists('\GuzzleHttp\Psr7\uri_for')
34+
? \GuzzleHttp\Psr7\uri_for('')
35+
: \GuzzleHttp\Psr7\Utils::uriFor('');
36+
37+
$this->client->getConfig('base_uri')->shouldBeCalled()->willReturn($returnedUri);
3438

3539
$this->setupMock('GET', $this->path, null, [], 'GET_image');
3640

@@ -123,7 +127,10 @@ public function test_it_deactivates()
123127

124128
public function test_it_uploads_data_stream()
125129
{
126-
$stream = \GuzzleHttp\Psr7\stream_for('data');
130+
$stream = function_exists('\GuzzleHttp\Psr7\stream_for')
131+
? \GuzzleHttp\Psr7\stream_for('data')
132+
: \GuzzleHttp\Psr7\Utils::streamFor('data');
133+
127134
$headers = ['Content-Type' => 'application/octet-stream'];
128135

129136
$this->setupMock('PUT', $this->path . '/file', $stream, $headers, new Response(204));
@@ -133,7 +140,10 @@ public function test_it_uploads_data_stream()
133140

134141
public function test_it_downloads_data()
135142
{
136-
$stream = \GuzzleHttp\Psr7\stream_for('data');
143+
$stream = function_exists('\GuzzleHttp\Psr7\stream_for')
144+
? \GuzzleHttp\Psr7\stream_for('data')
145+
: \GuzzleHttp\Psr7\Utils::streamFor('data');
146+
137147
$headers = ['Content-Type' => 'application/octet-stream'];
138148
$response = new Response(200, $headers, $stream);
139149

tests/unit/Images/v2/ServiceTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@ public function setUp(): void
2323

2424
public function test_it_creates_image()
2525
{
26+
$returnedUri = function_exists('\GuzzleHttp\Psr7\uri_for')
27+
? \GuzzleHttp\Psr7\uri_for('')
28+
: \GuzzleHttp\Psr7\Utils::uriFor('');
29+
2630
$this->client
2731
->getConfig('base_uri')
2832
->shouldBeCalled()
29-
->willReturn(\GuzzleHttp\Psr7\uri_for(''));
33+
->willReturn($returnedUri);
3034

3135
$expectedJson = [
3236
"name" => "Ubuntu 12.10",
@@ -58,10 +62,14 @@ public function test_it_creates_image()
5862

5963
public function test_it_lists_images()
6064
{
65+
$returnedUri = function_exists('\GuzzleHttp\Psr7\uri_for')
66+
? \GuzzleHttp\Psr7\uri_for('')
67+
: \GuzzleHttp\Psr7\Utils::uriFor('');
68+
6169
$this->client
6270
->getConfig('base_uri')
6371
->shouldBeCalled()
64-
->willReturn(\GuzzleHttp\Psr7\uri_for(''));
72+
->willReturn($returnedUri);
6573

6674
$this->client
6775
->request('GET', 'v2/images', ['query' => ['limit' => 5], 'headers' => []])

tests/unit/ObjectStore/v1/Models/ContainerTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,9 @@ public function test_other_exceptions_are_thrown()
210210

211211
public function test_it_chunks_according_to_provided_segment_size()
212212
{
213-
/** @var \GuzzleHttp\Psr7\Stream $stream */
214-
$stream = \GuzzleHttp\Psr7\stream_for(implode('', range('A', 'X')));
213+
$stream = function_exists('\GuzzleHttp\Psr7\stream_for')
214+
? \GuzzleHttp\Psr7\stream_for(implode('', range('A', 'X')))
215+
: \GuzzleHttp\Psr7\Utils::streamFor(implode('', range('A', 'X')));
215216

216217
$data = [
217218
'name' => 'object',

0 commit comments

Comments
 (0)