Skip to content

Commit a91ae7d

Browse files
authored
Merge pull request #534 from asgrim/phpize-build-tool-finder-check-api-version
Ensure the build tool finder checks PHP API version in phpize
2 parents b6f78bf + cee6573 commit a91ae7d

3 files changed

Lines changed: 31 additions & 3 deletions

File tree

phpstan-baseline.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ parameters:
453453
-
454454
message: '#^Access to an undefined property Php\\PieUnitTest\\SelfManage\\BuildTools\\PhpizeBuildToolFinderTest\:\:\$phpBinaryPath\.$#'
455455
identifier: property.notFound
456-
count: 3
456+
count: 4
457457
path: test/unit/SelfManage/BuildTools/PhpizeBuildToolFinderTest.php
458458

459459
-

src/SelfManage/BuildTools/PhpizeBuildToolFinder.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,16 @@ public function check(TargetPlatform $targetPlatform): bool
3838
// intentionally ignored - just don't try to use the guessed phpize path
3939
}
4040

41+
$expectedApiVersion = $targetPlatform->phpBinaryPath->phpApiVersion();
42+
4143
foreach ($tools as $tool) {
42-
if (file_exists($tool) && is_executable($tool) && PhpizePath::looksLikeValidPhpize($tool)) {
44+
if (file_exists($tool) && is_executable($tool) && PhpizePath::looksLikeValidPhpize($tool, $expectedApiVersion)) {
4345
return true;
4446
}
4547

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

48-
if ($foundTool !== null && PhpizePath::looksLikeValidPhpize($foundTool)) {
50+
if ($foundTool !== null && PhpizePath::looksLikeValidPhpize($foundTool, $expectedApiVersion)) {
4951
return true;
5052
}
5153
}

test/unit/SelfManage/BuildTools/PhpizeBuildToolFinderTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public function testCheckWithPhpizeInPath(): void
3535
putenv('PATH=' . realpath(self::GOOD_PHPIZE_PATH));
3636

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

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

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

@@ -102,4 +104,28 @@ public function testCheckWithPhpizeGuessed(): void
102104

103105
putenv('PATH=' . $oldPath);
104106
}
107+
108+
public function testPhpizeForDifferentPhpApiVersionIsRejected(): void
109+
{
110+
$oldPath = getenv('PATH');
111+
putenv('PATH=' . realpath(self::GOOD_PHPIZE_PATH));
112+
113+
$mockPhpBinary = $this->createMock(PhpBinaryPath::class);
114+
$mockPhpBinary->method('phpApiVersion')->willReturn('20250925');
115+
(fn () => $this->phpBinaryPath = '/path/to/php')
116+
->bindTo($mockPhpBinary, PhpBinaryPath::class)();
117+
118+
self::assertFalse((new PhpizeBuildToolFinder([]))->check(new TargetPlatform(
119+
OperatingSystem::NonWindows,
120+
OperatingSystemFamily::Linux,
121+
$mockPhpBinary,
122+
Architecture::x86_64,
123+
ThreadSafetyMode::NonThreadSafe,
124+
1,
125+
null,
126+
null,
127+
)));
128+
129+
putenv('PATH=' . $oldPath);
130+
}
105131
}

0 commit comments

Comments
 (0)