Skip to content

Commit

Permalink
[Process] Improve test cleanup by unlinking in a finally block
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-daubois committed Nov 4, 2024
1 parent 32dfba3 commit b61fb1c
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions Tests/ExecutableFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,20 @@ public function testFindBatchExecutableOnWindows()

$target = tempnam(sys_get_temp_dir(), 'example-windows-executable');

touch($target);
touch($target.'.BAT');

$this->assertFalse(is_executable($target));
try {
touch($target);
touch($target.'.BAT');

putenv('PATH='.sys_get_temp_dir());
$this->assertFalse(is_executable($target));

$finder = new ExecutableFinder();
$result = $finder->find(basename($target), false);
putenv('PATH='.sys_get_temp_dir());

unlink($target);
unlink($target.'.BAT');
$finder = new ExecutableFinder();
$result = $finder->find(basename($target), false);
} finally {
unlink($target);
unlink($target.'.BAT');
}

$this->assertSamePath($target.'.BAT', $result);
}
Expand All @@ -148,15 +150,17 @@ public function testEmptyDirInPath()
{
putenv(sprintf('PATH=%s:', \dirname(\PHP_BINARY)));

touch('executable');
chmod('executable', 0700);

$finder = new ExecutableFinder();
$result = $finder->find('executable');
try {
touch('executable');
chmod('executable', 0700);

$this->assertSame('./executable', $result);
$finder = new ExecutableFinder();
$result = $finder->find('executable');

unlink('executable');
$this->assertSame('./executable', $result);
} finally {
unlink('executable');
}
}

private function assertSamePath($expected, $tested)
Expand Down

0 comments on commit b61fb1c

Please sign in to comment.