Skip to content
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
19 changes: 8 additions & 11 deletions src/Platform/TargetPhp/PhpBinaryPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Webmozart\Assert\Assert;

use function array_combine;
use function array_filter;
use function array_key_exists;
use function array_keys;
use function array_map;
Expand Down Expand Up @@ -349,16 +350,12 @@ public static function fromCurrentProcess(): self

private static function cleanWarningAndDeprecationsFromOutput(string $testOutput): string
{
$testOutput = explode("\n", $testOutput);

foreach ($testOutput as $key => $line) {
if (! preg_match('/^(Deprecated|Warning):/', $line)) {
continue;
}

unset($testOutput[$key]);
}

return implode("\n", $testOutput);
return implode(
"\n",
array_filter(
explode("\n", $testOutput),
static fn (string $line) => ! preg_match('/^(Deprecated|Warning|PHP Warning):/', $line),
),
);
}
}
9 changes: 9 additions & 0 deletions test/assets/valid-php-with-warnings.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

# These should be implicitly filtered out by PIE
echo "PHP Warning: PHP Startup: Unable to load dynamic library 'redis' (tried: /path/to/redis (dlopen(/path/to/redis, 0x0009): [...] in Unknown on line 0"
echo "Warning: PHP Startup: Unable to load dynamic library 'pdo_mysql' (tried: /path/to/pdo_mysql (/path/to/pdo_mysql: cannot open shared object file: No such file or directory), /path/to/pdo_mysql.so (/path/to/pdo_mysql.so: undefined symbol: mysqlnd_debug_std_no_trace_funcs)) in Unknown on line 0"
echo "Deprecated: Function unsafe_function() is deprecated since 1.5, use safe_replacement() instead in example.php on line 9"

# This is the expected output of PIE:
echo "PHP";
13 changes: 12 additions & 1 deletion test/unit/Platform/TargetPhp/PhpBinaryPathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
#[CoversClass(PhpBinaryPath::class)]
final class PhpBinaryPathTest extends TestCase
{
private const FAKE_PHP_EXECUTABLE = __DIR__ . '/../../../assets/fake-php.sh';
private const FAKE_PHP_EXECUTABLE = __DIR__ . '/../../../assets/fake-php.sh';
private const VALID_PHP_WITH_WARNINGS = __DIR__ . '/../../../assets/valid-php-with-warnings.sh';

public function testNonExistentPhpBinaryIsRejected(): void
{
Expand Down Expand Up @@ -83,6 +84,16 @@ public function testInvalidPhpBinaryIsRejected(): void
PhpBinaryPath::fromPhpBinaryPath(self::FAKE_PHP_EXECUTABLE);
}

public function testWarningsAndDeprecationsAreFiltered(): void
{
if (Platform::isWindows()) {
self::markTestSkipped('Bash script does not run on Windows.');
}

$phpBinary = PhpBinaryPath::fromPhpBinaryPath(self::VALID_PHP_WITH_WARNINGS);
self::assertSame(self::VALID_PHP_WITH_WARNINGS, $phpBinary->phpBinaryPath);
}

public function testVersionFromCurrentProcess(): void
{
$phpBinary = PhpBinaryPath::fromCurrentProcess();
Expand Down