Skip to content

Commit c28dd3d

Browse files
committed
move from defunct travis to github workflow
1 parent ec9d873 commit c28dd3d

12 files changed

+229
-64
lines changed

.github/PULL_REQUEST_TEMPLATE.md

+4
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,7 @@ $foo->doSomething();
4141
#### To Do
4242

4343
- [ ] If the PR is not complete but you want to discuss the approach, list what remains to be done here
44+
45+
#### Note
46+
47+
The CI runs the integration tests with all implementations. It is normal that not all tests succeed. When adding test cases, please check the output if the new test fails and if so report it to the affected implementations.

.github/workflows/.editorconfig

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[*.yml]
2+
indent_size = 2

.github/workflows/guzzle.yml

+24
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

+40
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

+19
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

+19
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

+19
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

+19
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

-44
This file was deleted.

README.md

+22-8
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

+59-11
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 <[email protected]>
@@ -46,11 +52,23 @@ 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+
}
58+
4959
return SlimUri::createFromString($uri);
5060
}
5161

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

5674
throw new \RuntimeException('Could not create URI. Check your config');
@@ -67,9 +85,9 @@ protected function buildStream($data)
6785
if ($factory instanceof \Psr\Http\Message\StreamFactoryInterface) {
6886
if (is_string($data)) {
6987
return $factory->createStream($data);
70-
} else {
71-
return $factory->createStreamFromResource($data);
7288
}
89+
90+
return $factory->createStreamFromResource($data);
7391
}
7492

7593
throw new \RuntimeException('Constant "STREAM_FACTORY" must be a reference to a Http\Message\StreamFactory or \Psr\Http\Message\StreamFactoryInterface');
@@ -79,8 +97,26 @@ protected function buildStream($data)
7997
return \GuzzleHttp\Psr7\Utils::streamFor($data);
8098
}
8199

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

86122
throw new \RuntimeException('Could not create Stream. Check your config');
@@ -104,8 +140,20 @@ protected function buildUploadableFile($data)
104140
return new GuzzleUploadedFile($data, strlen($data), 0);
105141
}
106142

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

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

tests/RingCentral/StreamTest.php

+2-1
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)