|
29 | 29 | use function array_map; |
30 | 30 | use function array_unique; |
31 | 31 | use function assert; |
| 32 | +use function chmod; |
32 | 33 | use function count; |
33 | 34 | use function defined; |
34 | 35 | use function dirname; |
35 | 36 | use function file_exists; |
| 37 | +use function file_put_contents; |
36 | 38 | use function get_loaded_extensions; |
37 | 39 | use function ini_get; |
38 | 40 | use function is_dir; |
39 | 41 | use function is_executable; |
40 | 42 | use function mkdir; |
41 | | -use function php_uname; |
42 | 43 | use function phpversion; |
43 | 44 | use function sprintf; |
44 | 45 | use function strtolower; |
45 | 46 | use function sys_get_temp_dir; |
| 47 | +use function tempnam; |
46 | 48 | use function trim; |
47 | 49 | use function uniqid; |
| 50 | +use function unlink; |
48 | 51 |
|
49 | 52 | use const DIRECTORY_SEPARATOR; |
50 | 53 | use const PHP_INT_SIZE; |
@@ -240,15 +243,46 @@ public function testMajorMinorVersion(): void |
240 | 243 | ); |
241 | 244 | } |
242 | 245 |
|
243 | | - public function testMachineType(): void |
| 246 | + /** @return list<array{0: OperatingSystem, 1: string, 2: string, 3: int, 4: Architecture}> */ |
| 247 | + public static function machineTypeProvider(): array |
244 | 248 | { |
245 | | - $myUnameMachineType = php_uname('m'); |
246 | | - assert($myUnameMachineType !== ''); |
247 | | - self::assertSame( |
248 | | - Architecture::parseArchitecture($myUnameMachineType), |
249 | | - PhpBinaryPath::fromCurrentProcess() |
250 | | - ->machineType(), |
251 | | - ); |
| 249 | + return [ |
| 250 | + // x86 (32-bit) |
| 251 | + [OperatingSystem::Windows, 'Architecture => x32', '', 4, Architecture::x86], |
| 252 | + [OperatingSystem::NonWindows, 'Architecture => x86', 'x86', 4, Architecture::x86], |
| 253 | + [OperatingSystem::NonWindows, '', 'x86', 4, Architecture::x86], |
| 254 | + |
| 255 | + // x86_64 (64-bit) |
| 256 | + [OperatingSystem::Windows, 'Architecture => x64', 'AMD64', 8, Architecture::x86_64], |
| 257 | + [OperatingSystem::Windows, 'Architecture => x64', '', 8, Architecture::x86_64], |
| 258 | + [OperatingSystem::NonWindows, 'Architecture => x86_64', 'x86_64', 8, Architecture::x86_64], |
| 259 | + [OperatingSystem::NonWindows, '', 'x86_64', 8, Architecture::x86_64], |
| 260 | + |
| 261 | + // arm64 |
| 262 | + [OperatingSystem::NonWindows, 'Architecture => arm64', 'arm64', 8, Architecture::arm64], |
| 263 | + [OperatingSystem::NonWindows, '', 'arm64', 8, Architecture::arm64], |
| 264 | + [OperatingSystem::NonWindows, 'Architecture => aarch64', 'aarch64', 8, Architecture::arm64], |
| 265 | + [OperatingSystem::NonWindows, '', 'aarch64', 8, Architecture::arm64], |
| 266 | + ]; |
| 267 | + } |
| 268 | + |
| 269 | + #[RequiresOperatingSystemFamily('Linux')] |
| 270 | + #[DataProvider('machineTypeProvider')] |
| 271 | + public function testMachineType(OperatingSystem $os, string $phpinfo, string $uname, int $phpIntSize, Architecture $expectedArchitecture): void |
| 272 | + { |
| 273 | + $tmpSh = tempnam(sys_get_temp_dir(), uniqid('pie_machine_type_test')); |
| 274 | + file_put_contents($tmpSh, "#!/usr/bin/env bash\necho \"" . $uname . "\";\n"); |
| 275 | + chmod($tmpSh, 0777); |
| 276 | + |
| 277 | + $phpBinary = $this->createPartialMock(PhpBinaryPath::class, ['operatingSystem', 'phpinfo', 'phpIntSize']); |
| 278 | + (new ReflectionMethod($phpBinary, '__construct'))->invoke($phpBinary, $tmpSh, null); |
| 279 | + |
| 280 | + $phpBinary->method('operatingSystem')->willReturn($os); |
| 281 | + $phpBinary->method('phpinfo')->willReturn($phpinfo); |
| 282 | + $phpBinary->method('phpIntSize')->willReturn($phpIntSize); |
| 283 | + |
| 284 | + self::assertEquals($expectedArchitecture, $phpBinary->machineType()); |
| 285 | + unlink($tmpSh); |
252 | 286 | } |
253 | 287 |
|
254 | 288 | public function testPhpIntSize(): void |
|
0 commit comments