Skip to content

Commit

Permalink
Merge pull request #65 from alexpott/php8-compatibility
Browse files Browse the repository at this point in the history
* fix PHP 8.0-RC1, 7.4.12, 7.3.24 notices calling `stream_wrapper_restore`
* run tests on `symfony/phpunit-bridge` instead of `phpunit/phpunit`
  • Loading branch information
ohader committed Nov 7, 2020
2 parents ea5c600 + b4ba66d commit 60131cb
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 11 deletions.
5 changes: 3 additions & 2 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ init:
- SET COMPOSER_NO_INTERACTION=1
- SET PHP=1 # This var is connected to PHP install cache
- SET ANSICON=121x90 (121x90)
- SET SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT=1

## Install PHP and composer, and run the appropriate composer command
install:
Expand All @@ -38,7 +39,7 @@ install:
- IF %PHP%==1 echo extension=php_fileinfo.dll >> php.ini
- IF %PHP%==1 echo extension=php_bz2.dll >> php.ini
- IF %PHP%==1 echo @php %%~dp0composer.phar %%* > composer.bat
- appveyor-retry appveyor DownloadFile https://getcomposer.org/composer.phar
- appveyor-retry appveyor DownloadFile https://getcomposer.org/composer-1.phar -FileName composer.phar
- cd c:\projects\php-project-workspace
# Remove xdebug dependency as performance testing is not relevant at this point.
- composer remove --dev --no-update ext-xdebug
Expand All @@ -50,4 +51,4 @@ install:
## Run the actual test
test_script:
- cd c:\projects\php-project-workspace
- vendor/bin/phpunit
- vendor/bin/simple-phpunit
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/.appveyor.yml export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.scrutinizer.yml export-ignore
/.travis.yml export-ignore
/phpunit.xml export-ignore
/tests/ export-ignore
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
.phpunit.result.cache
vendor/
composer.lock
33 changes: 33 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
build:
environment:
php: '7.2'
dependencies:
before:
- pecl install xdebug
- echo zend_extension=$(php-config --extension-dir)/xdebug.so >> $(php --ini | grep -F '/php.ini' | cut -d ':' -f 2)
nodes:
analysis:
project_setup:
override:
- 'true'
tests:
override:
- php-scrutinizer-run
-
command: phpcs-run
use_website_config: true
tests:
override:
- SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT=1 vendor/bin/simple-phpunit --colors
filter:
excluded_paths:
- 'tests/*'
checks:
php:
phpunit_assertions: true

coding_style:
php:
spaces:
around_operators:
concatenation: true
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ script:
- >
echo;
echo "Running tests";
vendor/bin/phpunit --colors
SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT=1 vendor/bin/simple-phpunit --colors
- >
echo;
echo "Running PHP lint";
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
"homepage": "https://typo3.org/",
"keywords": ["php", "phar", "stream-wrapper", "security"],
"require": {
"php": "^7.0",
"php": "^7.0 || ^8.0",
"ext-json": "*"
},
"require-dev": {
"ext-xdebug": "*",
"phpunit/phpunit": "^6.5"
"phpspec/prophecy": "^1.10",
"symfony/phpunit-bridge": "^5.1"
},
"suggest": {
"ext-fileinfo": "For PHP builtin file type guessing, otherwise uses internal processing"
Expand Down
5 changes: 4 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<phpunit
bootstrap="vendor/autoload.php"
backupGlobals="true"
colors="true"
processIsolation="true"
verbose="true">

<php>
<ini name="SYMFONY_PHPUNIT_REMOVE" value="symfony/yaml"/>
</php>
<testsuites>
<testsuite name="functional tests">
<directory>tests/Functional/</directory>
Expand Down
10 changes: 9 additions & 1 deletion src/PharStreamWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,15 @@ private function invokeInternalStreamWrapper(string $functionName, ...$arguments

private function restoreInternalSteamWrapper()
{
stream_wrapper_restore('phar');
if (PHP_VERSION_ID < 70324
|| PHP_VERSION_ID >= 70400 && PHP_VERSION_ID < 70412) {
stream_wrapper_restore('phar');
} else {
// with https://github.com/php/php-src/pull/6183 (PHP #76943) the
// behavior of `stream_wrapper_restore()` did change for
// PHP 8.0-RC1, 7.4.12 and 7.3.24
@stream_wrapper_restore('phar');
}
}

private function registerStreamWrapper()
Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/Interceptor/AbstractTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function directoryActionAllowsInvocationDataProvider(): array
public function directoryOpenAllowsInvocation(string $path)
{
$handle = opendir('phar://' . $path);
self::assertInternalType('resource', $handle);
self::assertIsResource($handle);
}

/**
Expand Down Expand Up @@ -372,7 +372,7 @@ public function urlStatDeniesInvocation(string $functionName, string $path)
public function streamOpenAllowsInvocationForFileOpen(string $allowedPath)
{
$handle = fopen('phar://' . $allowedPath . '/Resources/content.txt', 'r');
self::assertInternalType('resource', $handle);
self::assertIsResource($handle);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function cliToolIsExecuted(string $command)
['pipe', 'w'], // STDERR
];
$process = proc_open('php ' . $command, $descriptorSpecifications, $pipes);
static::assertInternalType('resource', $process);
static::assertIsResource($process);

$read = [$pipes[1], $pipes[2]]; // reading from process' STDOUT & STDERR
$write = null;
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/Phar/ReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function pharAliasDataProvider(): array
public function pharStubContentFlagCanBeResolved(string $path, array $expectations)
{
$reader = new Reader($path);
$this->assertContains(
$this->assertStringContainsString(
$expectations[self::STUB_CONTENT_FLAG],
$reader->resolveContainer()->getStub()->getContent()
);
Expand Down

0 comments on commit 60131cb

Please sign in to comment.