Skip to content

Commit 9a0b21b

Browse files
committed
move from defunct travis to github workflow
1 parent 5c7ea47 commit 9a0b21b

File tree

11 files changed

+222
-64
lines changed

11 files changed

+222
-64
lines changed

.github/workflows/.editorconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[*.yml]
2+
indent_size = 2

.github/workflows/guzzle.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Guzzle
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
jobs:
10+
latest:
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
15+
uses: ./.github/workflows/integration.yml
16+
with:
17+
php: ${{ matrix.php }}
18+
suite: Guzzle
19+
package: guzzlehttp/psr7
20+
21+
# - Laminas
22+
# - Slim
23+
# - Nyholm
24+
# - RingCentral

.github/workflows/integration.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
on:
2+
workflow_call:
3+
inputs:
4+
php:
5+
required: true
6+
type: string
7+
suite:
8+
required: true
9+
type: string
10+
package:
11+
required: true
12+
type: string
13+
14+
jobs:
15+
latest:
16+
name: ${{ inputs.suite }} PHP ${{ inputs.php }}
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v3
22+
23+
- name: Setup PHP
24+
uses: shivammathur/setup-php@v2
25+
with:
26+
php-version: ${{ inputs.php }}
27+
tools: composer
28+
coverage: none
29+
30+
- name: Install dependencies
31+
# we need to remove all dev dependencies to avoid failures due to php version constraints
32+
# then we install the dependencies
33+
# and finally require the implementation to test with source flag (to get integration test cases that might be excluded in git-attributes)
34+
run: |
35+
composer remove --dev guzzlehttp/psr7 laminas/laminas-diactoros nyholm/psr7 ringcentral/psr7 slim/psr7 --no-update
36+
composer update --no-interaction --no-progress
37+
composer require ${{ inputs.package }} --no-interaction --no-progress --prefer-source
38+
39+
- name: Execute tests
40+
run: composer test -- --testsuite ${{ inputs.suite }}

.github/workflows/laminas.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Laminas
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
jobs:
10+
latest:
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
15+
uses: ./.github/workflows/integration.yml
16+
with:
17+
php: ${{ matrix.php }}
18+
suite: Laminas
19+
package: laminas/laminas-diactoros

.github/workflows/nyholm.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Nyholm
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
jobs:
10+
latest:
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
15+
uses: ./.github/workflows/integration.yml
16+
with:
17+
php: ${{ matrix.php }}
18+
suite: Nyholm
19+
package: nyholm/psr7

.github/workflows/ringcentral.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: RingCentral
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
jobs:
10+
latest:
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
15+
uses: ./.github/workflows/integration.yml
16+
with:
17+
php: ${{ matrix.php }}
18+
suite: RingCentral
19+
package: ringcentral/psr7

.github/workflows/slim.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Slim
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
jobs:
10+
latest:
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
php: [ '8.0', '8.1', '8.2' ]
15+
uses: ./.github/workflows/integration.yml
16+
with:
17+
php: ${{ matrix.php }}
18+
suite: Slim
19+
package: slim/psr7

.travis.yml

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

README.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,22 @@
88

99
| PSR7 Implementation | Status |
1010
| ------------------- |:-------------:|
11-
| Guzzle | [![Guzzle](https://travis-matrix-badges.herokuapp.com/repos/php-http/psr7-integration-tests/branches/master/1)](https://travis-ci.org/php-http/psr7-integration-tests) |
12-
| Laminas | [![Laminas](https://travis-matrix-badges.herokuapp.com/repos/php-http/psr7-integration-tests/branches/master/2)](https://travis-ci.org/php-http/psr7-integration-tests) |
13-
| Slim | [![Slim](https://travis-matrix-badges.herokuapp.com/repos/php-http/psr7-integration-tests/branches/master/3)](https://travis-ci.org/php-http/psr7-integration-tests) |
14-
| Nyholm | [![Nyholm](https://travis-matrix-badges.herokuapp.com/repos/php-http/psr7-integration-tests/branches/master/4)](https://travis-ci.org/php-http/psr7-integration-tests) |
15-
| RingCentral | [![RingCentral](https://travis-matrix-badges.herokuapp.com/repos/php-http/psr7-integration-tests/branches/master/5)](https://travis-ci.org/php-http/psr7-integration-tests) |
11+
| Guzzle | [![Guzzle](https://github.com/php-http/psr7-integration-tests/actions/workflows/guzzle.yml/badge.svg)](https://github.com/php-http/psr7-integration-tests/actions/workflows/guzzle.yml) |
12+
| Laminas | [![Laminas](https://github.com/php-http/psr7-integration-tests/actions/workflows/laminas.yml/badge.svg)](https://github.com/php-http/psr7-integration-tests/actions/workflows/laminas.yml) |
13+
| Slim | [![Slim](https://github.com/php-http/psr7-integration-tests/actions/workflows/slim.yml/badge.svg)](https://github.com/php-http/psr7-integration-tests/actions/workflows/slim.yml) |
14+
| Nyholm | [![Nyholm](https://github.com/php-http/psr7-integration-tests/actions/workflows/nyholm.yml/badge.svg)](https://github.com/php-http/psr7-integration-tests/actions/workflows/nyholm.yml) |
15+
| RingCentral | [![RingCentral](https://github.com/php-http/psr7-integration-tests/actions/workflows/ringcentral.yml/badge.svg)](https://github.com/php-http/psr7-integration-tests/actions/workflows/ringcentral.yml) |
16+
1617

1718
## Install
1819

19-
Via Composer
20+
To use the integration tests with a PSR-7 implementation, add this package to the dev dependencies:
2021

2122
``` bash
2223
$ composer require --dev php-http/psr7-integration-tests
2324
```
2425

26+
Then set up phpunit to run the tests for your implementation.
2527

2628
## Documentation
2729

@@ -30,14 +32,26 @@ Please see the [official documentation](http://docs.php-http.org/en/latest).
3032

3133
## Testing
3234

35+
This repository also is set up to test a couple of implementations directly. You need to install dependencies from source for the tests to work:
36+
37+
``` bash
38+
$ composer update --prefer-source
39+
```
40+
41+
**Note:** If you already have the sources installed, you need to delete the vendor folder before running the above command.
42+
43+
Run the test suite for one implementation with:
44+
3345
``` bash
34-
$ composer test
46+
$ composer test -- --testsuite <name>
3547
```
3648

49+
The names are `Guzzle`, `Laminas`, `Slim`, `Nyholm`, `RingCentral`.
50+
3751
It is also possible to exclude tests that require a live internet connection:
3852

3953
``` bash
40-
$ composer test -- --exclude-group internet
54+
$ composer test -- --testsuite <name> --exclude-group internet
4155
```
4256

4357
## Contributing

src/BaseTest.php

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@
55
use GuzzleHttp\Psr7\Stream as GuzzleStream;
66
use GuzzleHttp\Psr7\UploadedFile as GuzzleUploadedFile;
77
use GuzzleHttp\Psr7\Uri as GuzzleUri;
8+
use Laminas\Diactoros\StreamFactory as LaminasStreamFactory;
9+
use Laminas\Diactoros\Uri as LaminasUri;
10+
use Laminas\Diactoros\UploadedFile as LaminasUploadedFile;
11+
use Nyholm\Psr7\Factory\Psr17Factory as NyholmFactory;
812
use PHPUnit\Framework\TestCase;
913
use Psr\Http\Message\UriInterface;
14+
use RingCentral\Psr7\Uri as RingCentralUri;
15+
use function RingCentral\Psr7\stream_for as ring_central_stream_for;
1016
use Slim\Psr7\Uri as SlimUri;
11-
use Zend\Diactoros\Stream as ZendStream;
12-
use Zend\Diactoros\Uri as ZendUri;
13-
use Zend\Diactoros\UploadedFile as ZendUploadedFile;
17+
use Slim\Psr7\Factory\UriFactory as SlimUriFactory;
18+
use Slim\Psr7\Factory\StreamFactory as SlimStreamFactory;
19+
use Slim\Psr7\Factory\UploadedFileFactory as SlimUploadedFileFactory;
1420

1521
/**
1622
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
@@ -46,11 +52,22 @@ protected function buildUri($uri)
4652
}
4753

4854
if (class_exists(SlimUri::class)) {
55+
if (class_exists(SlimUriFactory::class)) {
56+
return (new SlimUriFactory())->createUri($uri);
57+
}
4958
return SlimUri::createFromString($uri);
5059
}
5160

52-
if (class_exists(ZendUri::class)) {
53-
return new ZendUri($uri);
61+
if (class_exists(LaminasUri::class)) {
62+
return new LaminasUri($uri);
63+
}
64+
65+
if (class_exists(NyholmFactory::class)) {
66+
return (new NyholmFactory())->createUri($uri);
67+
}
68+
69+
if (class_exists(RingCentralUri::class)) {
70+
return new RingCentralUri($uri);
5471
}
5572

5673
throw new \RuntimeException('Could not create URI. Check your config');
@@ -67,9 +84,8 @@ protected function buildStream($data)
6784
if ($factory instanceof \Psr\Http\Message\StreamFactoryInterface) {
6885
if (is_string($data)) {
6986
return $factory->createStream($data);
70-
} else {
71-
return $factory->createStreamFromResource($data);
7287
}
88+
return $factory->createStreamFromResource($data);
7389
}
7490

7591
throw new \RuntimeException('Constant "STREAM_FACTORY" must be a reference to a Http\Message\StreamFactory or \Psr\Http\Message\StreamFactoryInterface');
@@ -79,8 +95,25 @@ protected function buildStream($data)
7995
return \GuzzleHttp\Psr7\Utils::streamFor($data);
8096
}
8197

82-
if (class_exists(ZendStream::class)) {
83-
return new ZendStream($data);
98+
$factory = null;
99+
if (class_exists(LaminasStreamFactory::class)) {
100+
$factory = new LaminasStreamFactory();
101+
}
102+
if (class_exists(NyholmFactory::class)) {
103+
$factory = new NyholmFactory();
104+
}
105+
if (class_exists(SlimStreamFactory::class)) {
106+
$factory = new SlimStreamFactory();
107+
}
108+
if ($factory) {
109+
if (is_string($data)) {
110+
return $factory->createStream($data);
111+
}
112+
return $factory->createStreamFromResource($data);
113+
}
114+
115+
if (function_exists('ring_central_stream_for')) {
116+
return ring_central_stream_for($data);
84117
}
85118

86119
throw new \RuntimeException('Could not create Stream. Check your config');
@@ -104,8 +137,20 @@ protected function buildUploadableFile($data)
104137
return new GuzzleUploadedFile($data, strlen($data), 0);
105138
}
106139

107-
if (class_exists(ZendUploadedFile::class)) {
108-
return new ZendUploadedFile($data, strlen($data), 0);
140+
if (class_exists(LaminasUploadedFile::class)) {
141+
return new LaminasUploadedFile($data, strlen($data), 0);
142+
}
143+
144+
if (class_exists(NyholmFactory::class)) {
145+
$stream = $this->buildStream($data);
146+
147+
return (new NyholmFactory())->createUploadedFile($stream);
148+
}
149+
150+
if (class_exists(SlimUploadedFileFactory::class)) {
151+
$stream = $this->buildStream($data);
152+
153+
return (new SlimUploadedFileFactory())->createUploadedFile($stream);
109154
}
110155

111156
throw new \RuntimeException('Could not create Stream. Check your config');

tests/RingCentral/StreamTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
namespace Http\Psr7Test\Tests\RingCentral;
44

55
use Http\Psr7Test\StreamIntegrationTest;
6+
use function RingCentral\Psr7\stream_for;
67

78
class StreamTest extends StreamIntegrationTest
89
{
910
public function createStream($data)
1011
{
11-
return \RingCentral\Psr7\Utils::streamFor($data);
12+
return stream_for($data);
1213
}
1314
}

0 commit comments

Comments
 (0)