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