Skip to content

Commit 5cdd400

Browse files
minor #58746 [Process] Improve test cleanup by unlinking in a finally 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
2 parents a56fe7b + b61fb1c commit 5cdd400

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

Tests/ExecutableFinderTest.php

+20-16
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,20 @@ public function testFindBatchExecutableOnWindows()
125125

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

128-
touch($target);
129-
touch($target.'.BAT');
130-
131-
$this->assertFalse(is_executable($target));
128+
try {
129+
touch($target);
130+
touch($target.'.BAT');
132131

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

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

138-
unlink($target);
139-
unlink($target.'.BAT');
136+
$finder = new ExecutableFinder();
137+
$result = $finder->find(basename($target), false);
138+
} finally {
139+
unlink($target);
140+
unlink($target.'.BAT');
141+
}
140142

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

151-
touch('executable');
152-
chmod('executable', 0700);
153-
154-
$finder = new ExecutableFinder();
155-
$result = $finder->find('executable');
153+
try {
154+
touch('executable');
155+
chmod('executable', 0700);
156156

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

159-
unlink('executable');
160+
$this->assertSame('./executable', $result);
161+
} finally {
162+
unlink('executable');
163+
}
160164
}
161165

162166
public function testFindBuiltInCommandOnWindows()

0 commit comments

Comments
 (0)