Skip to content

Commit

Permalink
Allow running under PHP 8 and PHPUnit 9.x
Browse files Browse the repository at this point in the history
- PHPUnit 9.3 is required to support PHP 8. PHPUnit 8.x will not be
  updated to support PHP 8 and will become unsupported in February 2021.

    - Methods that were removed from 9.x were migrated.

    - Prophecy will no longer be bundled with PHPUnit, but the
      replacement phpspec/prophecy-phpunit required PHP 7.3. To keep
      PHP 7.2 compatibility, weirdan/prophecy-shim is used as a
      "migration layer".

      Note: 2.0.1 was tagged incorrectly, hence it is avoided in the
      version constraint.

- http-factory-tests upgraded to 0.7 (allows installing on PHP 8)

- In PHP 8, fopen throws ValueError instead of triggering an error.
  In PHP 7, that exception does not exist and PHPStan fails. Hence the
  symfony/polyfill-php80 dependency was brought.

- Some dependencies cannot be installed on PHP 8 yet (namely,
  fig/http-message-util and php-http/psr7-integration-tests).
  "--ignore-platform-reqs" was temporarily added to the CI build with
  PHP 'nightly'.
  • Loading branch information
edudobay committed Oct 10, 2020
1 parent 832912c commit bb96ff9
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ matrix:
- php: 7.4
env: ANALYSIS='true'
- php: nightly
env: IGNORE_PLATFORM_REQS='--ignore-platform-reqs'
allow_failures:
- php: nightly

before_script:
- if [[ "$ANALYSIS" == 'true' ]]; then composer require php-coveralls/php-coveralls:^2.2.0 ; fi
- composer install -n
- composer install -n "${IGNORE_PLATFORM_REQS:-}"

script:
- if [[ "$ANALYSIS" != 'true' ]]; then vendor/bin/phpunit ; fi
Expand Down
12 changes: 7 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,22 @@
}
],
"require": {
"php": "^7.2",
"php": "^7.2 || ^8.0",
"fig/http-message-util": "^1.1.4",
"psr/http-factory": "^1.0",
"psr/http-message": "^1.0",
"ralouphie/getallheaders": "^3"
"ralouphie/getallheaders": "^3",
"symfony/polyfill-php80": "^1.18"
},
"require-dev": {
"ext-json": "*",
"adriansuter/php-autoload-override": "^1.2",
"http-interop/http-factory-tests": "^0.6.0",
"http-interop/http-factory-tests": "^0.7.0",
"php-http/psr7-integration-tests": "dev-master",
"phpstan/phpstan": "^0.12",
"phpunit/phpunit": "^8.5",
"squizlabs/php_codesniffer": "^3.5"
"phpunit/phpunit": "^8.5 || ^9.3",
"squizlabs/php_codesniffer": "^3.5",
"weirdan/prophecy-shim": "^1.0 || 2.0.0 || >2.0.1"
},
"provide": {
"psr/http-message-implementation": "1.0",
Expand Down
11 changes: 10 additions & 1 deletion src/Factory/StreamFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,16 @@ public function createStreamFromFile(
));
});

$resource = fopen($filename, $mode);
try {
$resource = fopen($filename, $mode);
} catch (\ValueError $exception) {
throw new RuntimeException(sprintf(
'Unable to open %s using mode %s: %s',
$filename,
$mode,
$exception->getMessage()
));
}
restore_error_handler();

if ($exc) {
Expand Down
3 changes: 3 additions & 0 deletions tests/Factory/UploadedFileFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Interop\Http\Factory\UploadedFileFactoryTestCase;
use InvalidArgumentException;
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Http\Message\StreamInterface;
use Slim\Psr7\Factory\StreamFactory;
use Slim\Psr7\Factory\UploadedFileFactory;
Expand All @@ -24,6 +25,8 @@

class UploadedFileFactoryTest extends UploadedFileFactoryTestCase
{
use ProphecyTrait;

/**
* @return UploadedFileFactory
*/
Expand Down
3 changes: 3 additions & 0 deletions tests/StreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace Slim\Tests\Psr7;

use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use ReflectionException;
use ReflectionMethod;
use ReflectionProperty;
Expand All @@ -24,6 +25,8 @@

class StreamTest extends TestCase
{
use ProphecyTrait;

/**
* @var resource pipe stream file handle
*/
Expand Down
7 changes: 5 additions & 2 deletions tests/UploadedFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UploadedFileInterface;
use ReflectionProperty;
Expand Down Expand Up @@ -42,6 +43,8 @@

class UploadedFileTest extends TestCase
{
use ProphecyTrait;

private static $filename = './phpUxcOty';

private static $tmpFiles = ['./phpUxcOty'];
Expand Down Expand Up @@ -245,7 +248,7 @@ public function testMoveTo(UploadedFile $uploadedFile)
public function testMoveToRenameFailure()
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessageRegExp('/^Error moving uploaded file .* to .*$/');
$this->expectExceptionMessageMatches('/^Error moving uploaded file .* to .*$/');

$uploadedFile = $this->generateNewTmpFile();

Expand Down Expand Up @@ -280,7 +283,7 @@ public function testMoveToSapiNonUploadedFile(UploadedFile $uploadedFile)
public function testMoveToSapiMoveUploadedFileFails(UploadedFile $uploadedFile)
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessageRegExp('~Error moving uploaded file.*~');
$this->expectExceptionMessageMatches('~Error moving uploaded file.*~');

$GLOBALS['is_uploaded_file_return'] = true;

Expand Down

0 comments on commit bb96ff9

Please sign in to comment.