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
2 changes: 1 addition & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ parameters:
-
message: '#^Access to an undefined property Php\\PieUnitTest\\SelfManage\\BuildTools\\PhpizeBuildToolFinderTest\:\:\$phpBinaryPath\.$#'
identifier: property.notFound
count: 3
count: 4
path: test/unit/SelfManage/BuildTools/PhpizeBuildToolFinderTest.php

-
Expand Down
6 changes: 4 additions & 2 deletions src/SelfManage/BuildTools/PhpizeBuildToolFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ public function check(TargetPlatform $targetPlatform): bool
// intentionally ignored - just don't try to use the guessed phpize path
}

$expectedApiVersion = $targetPlatform->phpBinaryPath->phpApiVersion();

foreach ($tools as $tool) {
if (file_exists($tool) && is_executable($tool) && PhpizePath::looksLikeValidPhpize($tool)) {
if (file_exists($tool) && is_executable($tool) && PhpizePath::looksLikeValidPhpize($tool, $expectedApiVersion)) {
return true;
}

$foundTool = (new ExecutableFinder())->find($tool);

if ($foundTool !== null && PhpizePath::looksLikeValidPhpize($foundTool)) {
if ($foundTool !== null && PhpizePath::looksLikeValidPhpize($foundTool, $expectedApiVersion)) {
return true;
}
}
Expand Down
26 changes: 26 additions & 0 deletions test/unit/SelfManage/BuildTools/PhpizeBuildToolFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function testCheckWithPhpizeInPath(): void
putenv('PATH=' . realpath(self::GOOD_PHPIZE_PATH));

$mockPhpBinary = $this->createMock(PhpBinaryPath::class);
$mockPhpBinary->method('phpApiVersion')->willReturn('20240924');
(fn () => $this->phpBinaryPath = '/path/to/php')
->bindTo($mockPhpBinary, PhpBinaryPath::class)();

Expand All @@ -58,6 +59,7 @@ public function testCheckWithPhpizeFromTargetPlatform(): void
putenv('PATH=' . realpath(self::BAD_PHPIZE_PATH));

$mockPhpBinary = $this->createMock(PhpBinaryPath::class);
$mockPhpBinary->method('phpApiVersion')->willReturn('20240924');
(fn () => $this->phpBinaryPath = '/path/to/php')
->bindTo($mockPhpBinary, PhpBinaryPath::class)();

Expand Down Expand Up @@ -102,4 +104,28 @@ public function testCheckWithPhpizeGuessed(): void

putenv('PATH=' . $oldPath);
}

public function testPhpizeForDifferentPhpApiVersionIsRejected(): void
{
$oldPath = getenv('PATH');
putenv('PATH=' . realpath(self::GOOD_PHPIZE_PATH));

$mockPhpBinary = $this->createMock(PhpBinaryPath::class);
$mockPhpBinary->method('phpApiVersion')->willReturn('20250925');
(fn () => $this->phpBinaryPath = '/path/to/php')
->bindTo($mockPhpBinary, PhpBinaryPath::class)();

self::assertFalse((new PhpizeBuildToolFinder([]))->check(new TargetPlatform(
OperatingSystem::NonWindows,
OperatingSystemFamily::Linux,
$mockPhpBinary,
Architecture::x86_64,
ThreadSafetyMode::NonThreadSafe,
1,
null,
null,
)));

putenv('PATH=' . $oldPath);
}
}