diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 484f95bd..a5b3a736 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -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 - diff --git a/src/SelfManage/BuildTools/PhpizeBuildToolFinder.php b/src/SelfManage/BuildTools/PhpizeBuildToolFinder.php index ec10cf3a..305ac5f8 100644 --- a/src/SelfManage/BuildTools/PhpizeBuildToolFinder.php +++ b/src/SelfManage/BuildTools/PhpizeBuildToolFinder.php @@ -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; } } diff --git a/test/unit/SelfManage/BuildTools/PhpizeBuildToolFinderTest.php b/test/unit/SelfManage/BuildTools/PhpizeBuildToolFinderTest.php index 067bf32d..3a50a0c1 100644 --- a/test/unit/SelfManage/BuildTools/PhpizeBuildToolFinderTest.php +++ b/test/unit/SelfManage/BuildTools/PhpizeBuildToolFinderTest.php @@ -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)(); @@ -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)(); @@ -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); + } }