Skip to content

move from defunct travis to github workflow #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ $foo->doSomething();
#### To Do

- [ ] If the PR is not complete but you want to discuss the approach, list what remains to be done here

#### Note

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.
2 changes: 2 additions & 0 deletions .github/workflows/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[*.yml]
indent_size = 2
24 changes: 24 additions & 0 deletions .github/workflows/guzzle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Guzzle

on:
push:
branches:
- master
pull_request:

jobs:
latest:
strategy:
fail-fast: false
matrix:
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
uses: ./.github/workflows/integration.yml
with:
php: ${{ matrix.php }}
suite: Guzzle
package: guzzlehttp/psr7

# - Laminas
# - Slim
# - Nyholm
# - RingCentral
40 changes: 40 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
on:
workflow_call:
inputs:
php:
required: true
type: string
suite:
required: true
type: string
package:
required: true
type: string

jobs:
latest:
name: ${{ inputs.suite }} PHP ${{ inputs.php }}
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.php }}
tools: composer
coverage: none

- name: Install dependencies
# we need to remove all dev dependencies to avoid failures due to php version constraints
# then we install the dependencies
# and finally require the implementation to test with source flag (to get integration test cases that might be excluded in git-attributes)
run: |
composer remove --dev guzzlehttp/psr7 laminas/laminas-diactoros nyholm/psr7 ringcentral/psr7 slim/psr7 --no-update
composer update --no-interaction --no-progress
composer require ${{ inputs.package }} --no-interaction --no-progress --prefer-source

- name: Execute tests
run: composer test -- --testsuite ${{ inputs.suite }}
19 changes: 19 additions & 0 deletions .github/workflows/laminas.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Laminas

on:
push:
branches:
- master
pull_request:

jobs:
latest:
strategy:
fail-fast: false
matrix:
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
uses: ./.github/workflows/integration.yml
with:
php: ${{ matrix.php }}
suite: Laminas
package: laminas/laminas-diactoros
19 changes: 19 additions & 0 deletions .github/workflows/nyholm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Nyholm

on:
push:
branches:
- master
pull_request:

jobs:
latest:
strategy:
fail-fast: false
matrix:
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
uses: ./.github/workflows/integration.yml
with:
php: ${{ matrix.php }}
suite: Nyholm
package: nyholm/psr7
19 changes: 19 additions & 0 deletions .github/workflows/ringcentral.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: RingCentral

on:
push:
branches:
- master
pull_request:

jobs:
latest:
strategy:
fail-fast: false
matrix:
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
uses: ./.github/workflows/integration.yml
with:
php: ${{ matrix.php }}
suite: RingCentral
package: ringcentral/psr7
19 changes: 19 additions & 0 deletions .github/workflows/slim.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Slim

on:
push:
branches:
- master
pull_request:

jobs:
latest:
strategy:
fail-fast: false
matrix:
php: [ '8.0', '8.1', '8.2' ]
uses: ./.github/workflows/integration.yml
with:
php: ${{ matrix.php }}
suite: Slim
package: slim/psr7
44 changes: 0 additions & 44 deletions .travis.yml

This file was deleted.

30 changes: 22 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@

| PSR7 Implementation | Status |
| ------------------- |:-------------:|
| 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) |
| 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) |
| 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) |
| 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) |
| 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) |
| 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) |
| 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) |
| 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) |
| 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) |
| 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) |


## Install

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

``` bash
$ composer require --dev php-http/psr7-integration-tests
```

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

## Documentation

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

## Testing

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:

``` bash
$ composer update --prefer-source
```

**Note:** If you already have the sources installed, you need to delete the vendor folder before running the above command.

Run the test suite for one implementation with:

``` bash
$ composer test
$ composer test -- --testsuite <name>
```

The names are `Guzzle`, `Laminas`, `Slim`, `Nyholm`, `RingCentral`.

It is also possible to exclude tests that require a live internet connection:

``` bash
$ composer test -- --exclude-group internet
$ composer test -- --testsuite <name> --exclude-group internet
```

## Contributing
Expand Down
70 changes: 59 additions & 11 deletions src/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@
use GuzzleHttp\Psr7\Stream as GuzzleStream;
use GuzzleHttp\Psr7\UploadedFile as GuzzleUploadedFile;
use GuzzleHttp\Psr7\Uri as GuzzleUri;
use Laminas\Diactoros\StreamFactory as LaminasStreamFactory;
use Laminas\Diactoros\Uri as LaminasUri;
use Laminas\Diactoros\UploadedFile as LaminasUploadedFile;
use Nyholm\Psr7\Factory\Psr17Factory as NyholmFactory;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\UriInterface;
use RingCentral\Psr7\Uri as RingCentralUri;
use function RingCentral\Psr7\stream_for as ring_central_stream_for;
use Slim\Psr7\Uri as SlimUri;
use Zend\Diactoros\Stream as ZendStream;
use Zend\Diactoros\Uri as ZendUri;
use Zend\Diactoros\UploadedFile as ZendUploadedFile;
use Slim\Psr7\Factory\UriFactory as SlimUriFactory;
use Slim\Psr7\Factory\StreamFactory as SlimStreamFactory;
use Slim\Psr7\Factory\UploadedFileFactory as SlimUploadedFileFactory;

/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
Expand Down Expand Up @@ -46,11 +52,23 @@ protected function buildUri($uri)
}

if (class_exists(SlimUri::class)) {
if (class_exists(SlimUriFactory::class)) {
return (new SlimUriFactory())->createUri($uri);
}

return SlimUri::createFromString($uri);
}

if (class_exists(ZendUri::class)) {
return new ZendUri($uri);
if (class_exists(LaminasUri::class)) {
return new LaminasUri($uri);
}

if (class_exists(NyholmFactory::class)) {
return (new NyholmFactory())->createUri($uri);
}

if (class_exists(RingCentralUri::class)) {
return new RingCentralUri($uri);
}

throw new \RuntimeException('Could not create URI. Check your config');
Expand All @@ -67,9 +85,9 @@ protected function buildStream($data)
if ($factory instanceof \Psr\Http\Message\StreamFactoryInterface) {
if (is_string($data)) {
return $factory->createStream($data);
} else {
return $factory->createStreamFromResource($data);
}

return $factory->createStreamFromResource($data);
}

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

if (class_exists(ZendStream::class)) {
return new ZendStream($data);
$factory = null;
if (class_exists(LaminasStreamFactory::class)) {
$factory = new LaminasStreamFactory();
}
if (class_exists(NyholmFactory::class)) {
$factory = new NyholmFactory();
}
if (class_exists(SlimStreamFactory::class)) {
$factory = new SlimStreamFactory();
}
if ($factory) {
if (is_string($data)) {
return $factory->createStream($data);
}

return $factory->createStreamFromResource($data);
}

if (function_exists('ring_central_stream_for')) {
return ring_central_stream_for($data);
}

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

if (class_exists(ZendUploadedFile::class)) {
return new ZendUploadedFile($data, strlen($data), 0);
if (class_exists(LaminasUploadedFile::class)) {
return new LaminasUploadedFile($data, strlen($data), 0);
}

if (class_exists(NyholmFactory::class)) {
$stream = $this->buildStream($data);

return (new NyholmFactory())->createUploadedFile($stream);
}

if (class_exists(SlimUploadedFileFactory::class)) {
$stream = $this->buildStream($data);

return (new SlimUploadedFileFactory())->createUploadedFile($stream);
}

throw new \RuntimeException('Could not create Stream. Check your config');
Expand Down
3 changes: 2 additions & 1 deletion tests/RingCentral/StreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
namespace Http\Psr7Test\Tests\RingCentral;

use Http\Psr7Test\StreamIntegrationTest;
use function RingCentral\Psr7\stream_for;

class StreamTest extends StreamIntegrationTest
{
public function createStream($data)
{
return \RingCentral\Psr7\Utils::streamFor($data);
return stream_for($data);
}
}