Skip to content

run tests with PHPUnit 12.1 on PHP >= 8.3 #61333

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
Aug 5, 2025
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
2 changes: 1 addition & 1 deletion phpunit
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if (!file_exists(__DIR__.'/vendor/symfony/phpunit-bridge/bin/simple-phpunit')) {
}
if (!getenv('SYMFONY_PHPUNIT_VERSION')) {
if (\PHP_VERSION_ID >= 80300) {
putenv('SYMFONY_PHPUNIT_VERSION=12.0');
putenv('SYMFONY_PHPUNIT_VERSION=12.1');
} else {
putenv('SYMFONY_PHPUNIT_VERSION=11.5');
}
Expand Down
15 changes: 5 additions & 10 deletions src/Symfony/Component/Process/Tests/ExecutableFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\ExecutableFinder;
use Symfony\Component\Process\Process;

/**
* @author Chris Smith <chris@cs278.org>
Expand Down Expand Up @@ -122,17 +123,11 @@ public function testFindWithOpenBaseDir()
$this->markTestSkipped('Cannot test when open_basedir is set');
}

putenv('PATH='.\dirname(\PHP_BINARY));
$initialOpenBaseDir = ini_set('open_basedir', \dirname(\PHP_BINARY).\PATH_SEPARATOR.'/');

try {
$finder = new ExecutableFinder();
$result = $finder->find($this->getPhpBinaryName());
$process = new Process([\PHP_BINARY, '-d', 'open_basedir='.\dirname(\PHP_BINARY).\PATH_SEPARATOR.'/', __DIR__.'/Fixtures/open_basedir.php']);
$process->run();
$result = $process->getOutput();

$this->assertSamePath(\PHP_BINARY, $result);
} finally {
ini_set('open_basedir', $initialOpenBaseDir);
Copy link
Member Author

@xabbuh xabbuh Aug 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This never used to work as expected as you cannot widen the open basedir restrictions after tightening it before. Later on when PHPUnit cleaned up the test environment this led to a PHP warning which in turn lets the test fail:

src/Symfony/Component/Process                                                19s
+ /home/runner/work/symfony/symfony/phpunit --exclude-group tty --exclude-group benchmark --exclude-group intl-data --exclude-group integration --exclude-group transient src/Symfony/Component/Process
PHPUnit 12.1.6 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.23
Configuration: /home/runner/work/symfony/symfony/phpunit.xml.dist

........WS.S...................................................  63 / 186 ( 33%)
...................SSS......................................... 126 / 186 ( 67%)
...........................................................S    186 / 186 (100%)

Time: 00:19.259, Memory: 16.00 MB

1 test triggered 1 PHP warning:

1) /home/runner/work/symfony/symfony/.phpunit/phpunit-12.1-0/src/Framework/TestCase.php:1290
ini_set(): open_basedir restriction in effect. File() is not within the allowed path(s): (/usr/bin:/)

Triggered by:

* Symfony\Component\Process\Tests\ExecutableFinderTest::testFindWithOpenBaseDir
  /home/runner/work/symfony/symfony/src/Symfony/Component/Process/Tests/ExecutableFinderTest.php:115

}
$this->assertSamePath(\PHP_BINARY, $result);
}

#[RunInSeparateProcess]
Expand Down
23 changes: 23 additions & 0 deletions src/Symfony/Component/Process/Tests/Fixtures/open_basedir.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

require_once __DIR__.'/../../ExecutableFinder.php';

use Symfony\Component\Process\ExecutableFinder;

putenv('PATH='.dirname(PHP_BINARY));

function getPhpBinaryName(): string
{
return basename(PHP_BINARY, '\\' === DIRECTORY_SEPARATOR ? '.exe' : '');
}

echo (new ExecutableFinder())->find(getPhpBinaryName());