Skip to content

Commit

Permalink
Merge 7c10414 into 0ea58d2
Browse files Browse the repository at this point in the history
  • Loading branch information
edudobay committed Nov 1, 2020
2 parents 0ea58d2 + 7c10414 commit 4662b62
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
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
17 changes: 11 additions & 6 deletions composer.json
Expand Up @@ -28,20 +28,22 @@
}
],
"require": {
"php": "^7.2",
"fig/http-message-util": "^1.1.4",
"php": "^7.2 || ^8.0",
"fig/http-message-util": "dev-php8@dev",
"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.2"
},
"provide": {
"psr/http-message-implementation": "1.0",
Expand All @@ -67,6 +69,9 @@
"phpcs": "phpcs",
"phpstan": "phpstan analyse src --memory-limit=-1"
},
"repositories": [
{ "type": "git", "url": "https://github.com/m-ober/http-message-util.git" }
],
"config": {
"sort-packages": true
}
Expand Down
23 changes: 19 additions & 4 deletions src/Factory/StreamFactory.php
Expand Up @@ -53,20 +53,35 @@ public function createStreamFromFile(
string $mode = 'r',
StreamInterface $cache = null
): StreamInterface {
// When fopen fails, PHP normally raises a warning. Add an error
// When fopen fails, PHP 7 normally raises a warning. Add an error
// handler to check for errors and throw an exception instead.
// On PHP 8, exceptions are thrown.
$exc = null;

set_error_handler(function (int $errno, string $errstr) use ($filename, $mode, &$exc) {
// Would not be initialized if fopen throws on PHP >= 8.0
$resource = null;

$errorHandler = function (string $errorMessage) use ($filename, $mode, &$exc) {
$exc = new RuntimeException(sprintf(
'Unable to open %s using mode %s: %s',
$filename,
$mode,
$errstr
$errorMessage
));
};

set_error_handler(function (int $errno, string $errstr) use ($errorHandler) {
$errorHandler($errstr);
});

$resource = fopen($filename, $mode);
try {
$resource = fopen($filename, $mode);
// @codeCoverageIgnoreStart
// (Can only be executed in PHP >= 8.0)
} catch (\ValueError $exception) {
$errorHandler($exception->getMessage());
}
// @codeCoverageIgnoreEnd
restore_error_handler();

if ($exc) {
Expand Down
2 changes: 1 addition & 1 deletion src/UploadedFile.php
Expand Up @@ -208,7 +208,7 @@ public function getSize(): ?int
{
return $this->size;
}

/**
* Returns the client-provided full path to the file
*
Expand Down
3 changes: 3 additions & 0 deletions tests/Factory/UploadedFileFactoryTest.php
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
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
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 4662b62

Please sign in to comment.