<?phpnamespace Tests;use PHPUnit\Framework\TestCase;final class RelaunchTest extends TestCase{ /** @return string what the new WinZik wrote: 'started' (it got the lock) or 'blocked' */ private function relaunch(string $how): string { $dir = sys_get_temp_dir() . '/wz-relaunch-' . getmypid() . '-' . $how; @mkdir($dir); @unlink("$dir/result"); // the old WinZik as installed (not a test run: Relaunch starts nothing in the tests) $env = array_diff_key(getenv(), ['JUMPHP_SMOKE' => 1, 'JUMPHP_SCREENSHOT' => 1, 'JUMPHP_TEST' => 1]); $old = proc_open([PHP_BINARY, __DIR__ . '/fixtures/relaunch-old.php', "$dir/lock", "$dir/result", $how], [1 => ['file', '/dev/null', 'w'], 2 => ['file', '/dev/null', 'w']], $pipes, null, $env); self::assertIsResource($old); proc_close($old); $until = microtime(true) + 15; while (!is_file("$dir/result") && microtime(true) < $until) { usleep(100000); } return (string)@file_get_contents("$dir/result"); } public function testTheNewWinZikStartsOnceTheOldOneEndedWithItsLockFree(): void { self::assertSame('started', $this->relaunch('relaunch')); } public function testTheOldWayLeftTheNewOneHoldingTheOldLockItself(): void { // the cause of "a window not drawn, then nothing": the inherited lock self::assertSame('blocked', $this->relaunch('old')); }}