Skip to content

Commit

Permalink
minor #58746 [Process] Improve test cleanup by unlinking in a `finall…
Browse files Browse the repository at this point in the history
…y` block (alexandre-daubois)

This PR was merged into the 5.4 branch.

Discussion
----------

[Process] Improve test cleanup by unlinking in a `finally` block

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Issues        | -
| License       | MIT

Follwup for #58711, I realized afterwards that we may unlink in `finally` block to ensure proper test clean up in case something goes wrong.

Commits
-------

5c547c958b9 [Process] Improve test cleanup by unlinking in a `finally` block
  • Loading branch information
nicolas-grekas committed Nov 4, 2024
2 parents a56fe7b + b61fb1c commit 5cdd400
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');
}
}

public function testFindBuiltInCommandOnWindows()
Expand Down

0 comments on commit 5cdd400

Please sign in to comment.