Skip to content

Commit

Permalink
Upgrade to phpunit 10
Browse files Browse the repository at this point in the history
* Normalize class import and class alias
* Remove PHP7.2 from github workflows
* Migrate phpunit.xml.dist configuration file
* Using FQN for PSR interfaces
  • Loading branch information
nyamsprod authored and dbu committed Mar 25, 2024
1 parent efc8dd3 commit e5c7059
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 96 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/guzzle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
php: [ '7.3', '7.4', '8.0', '8.1', '8.2' ]
uses: ./.github/workflows/integration.yml
with:
php: ${{ matrix.php }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/laminas-legacy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ '7.2', '7.3', '7.4' ]
php: [ '7.3', '7.4' ]
uses: ./.github/workflows/integration.yml
with:
php: ${{ matrix.php }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nyholm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
php: [ '7.3', '7.4', '8.0', '8.1', '8.2' ]
uses: ./.github/workflows/integration.yml
with:
php: ${{ matrix.php }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ringcentral.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
php: [ '7.3', '7.4', '8.0', '8.1', '8.2' ]
uses: ./.github/workflows/integration.yml
with:
php: ${{ matrix.php }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/.tmp
/.phpunit.result.cache
/.phpunit.cache
/behat.yml
/build/
/composer.lock
Expand Down
47 changes: 19 additions & 28 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,48 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="true"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="vendor/autoload.php"
>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
colors="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="vendor/autoload.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
cacheDirectory=".phpunit.cache"
backupStaticProperties="true"
>
<coverage>
<include>
<directory>./src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Guzzle">
<directory>./tests/Guzzle/</directory>
</testsuite>

<testsuite name="RingCentral">
<directory>./tests/RingCentral/</directory>
</testsuite>

<testsuite name="Slim">
<directory>./tests/Slim/</directory>
<directory>./tests/Slim/</directory>
</testsuite>

<testsuite name="Laminas">
<directory>./tests/Laminas/</directory>
<directory>./tests/Laminas/</directory>
</testsuite>

<testsuite name="Nyholm">
<directory>./vendor/nyholm/psr7/tests/Integration/</directory>
<directory>./vendor/nyholm/psr7/tests/Integration/</directory>
</testsuite>

<testsuite name="HttpSoft">
<directory>./vendor/httpsoft/http-message/tests/Integration/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./</directory>
<exclude>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
32 changes: 17 additions & 15 deletions src/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
use Laminas\Diactoros\Uri as LaminasUri;
use Laminas\Diactoros\UploadedFile as LaminasUploadedFile;
use Nyholm\Psr7\Factory\Psr17Factory as NyholmFactory;
use GuzzleHttp\Psr7\Utils;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\UploadedFileFactoryInterface;
use Psr\Http\Message\UriFactoryInterface;
use Psr\Http\Message\UriInterface;
use RingCentral\Psr7\Uri as RingCentralUri;
use function RingCentral\Psr7\stream_for as ring_central_stream_for;
use GuzzleHttp\Psr7\Utils as GuzzleUtils;
use Http\Message\StreamFactory as HttplugStreamFactory;
use Http\Message\UriFactory as HttplugUriFactory;
use Psr\Http\Message\StreamFactoryInterface as PsrStreamFactoryInterface;
use Psr\Http\Message\UploadedFileFactoryInterface as PsrUploadedFileFactoryInterface;
use Psr\Http\Message\UriFactoryInterface as PsrUriFactoryInterface;
use Psr\Http\Message\UriInterface as PsrUriInterface;
use Slim\Psr7\Uri as SlimUri;
use Slim\Psr7\Factory\UriFactory as SlimUriFactory;
use Slim\Psr7\Factory\StreamFactory as SlimStreamFactory;
Expand All @@ -40,18 +42,18 @@ protected function buildUri($uri)
if (defined('URI_FACTORY')) {
$factoryClass = URI_FACTORY;
$factory = new $factoryClass();
if ($factory instanceof UriFactory) {
if ($factory instanceof HttplugUriFactory) {
return $factory->createUri($uri);
}
if ($factory instanceof UriFactoryInterface) {
if ($uri instanceof UriInterface) {
if ($factory instanceof PsrUriFactoryInterface) {
if ($uri instanceof PsrUriInterface) {
return $uri;
}

return $factory->createUri($uri);
}

throw new \RuntimeException('Constant "URI_FACTORY" must be a reference to a Http\Message\UriFactory or \Psr\Http\Message\UriFactoryInterface');
throw new \RuntimeException('Constant "URI_FACTORY" must be a reference to a '.HttplugUriFactory::class.' or '.PsrUriFactoryInterface::class);
}

if (class_exists(HttpSoftUri::class)) {
Expand Down Expand Up @@ -90,22 +92,22 @@ protected function buildStream($data)
if (defined('STREAM_FACTORY')) {
$factoryClass = STREAM_FACTORY;
$factory = new $factoryClass();
if ($factory instanceof StreamFactory) {
if ($factory instanceof HttplugStreamFactory) {
return $factory->createStream($data);
}
if ($factory instanceof StreamFactoryInterface) {
if ($factory instanceof PsrStreamFactoryInterface) {
if (is_string($data)) {
return $factory->createStream($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');
throw new \RuntimeException('Constant "STREAM_FACTORY" must be a reference to a '.HttplugStreamFactory::class.' or '.PsrStreamFactoryInterface::class);
}

if (class_exists(GuzzleStream::class)) {
return Utils::streamFor($data);
return GuzzleUtils::streamFor($data);
}

$factory = null;
Expand Down Expand Up @@ -141,8 +143,8 @@ protected function buildUploadableFile($data)
if (defined('UPLOADED_FILE_FACTORY')) {
$factoryClass = UPLOADED_FILE_FACTORY;
$factory = new $factoryClass();
if (!$factory instanceof UploadedFileFactoryInterface) {
throw new \RuntimeException('Constant "UPLOADED_FILE_FACTORY" must be a reference to a Psr\Http\Message\UploadedFileFactoryInterface');
if (!$factory instanceof PsrUploadedFileFactoryInterface) {
throw new \RuntimeException('Constant "UPLOADED_FILE_FACTORY" must be a reference to a '.PsrUploadedFileFactoryInterface::class);
}

$stream = $this->buildStream($data);
Expand Down
Loading

0 comments on commit e5c7059

Please sign in to comment.