Skip to content

Commit 8ecad26

Browse files
Use directory copy instead of rename in integration tests
- Replace rename() with copyDirectory() + remove - Fixes cross-filesystem rename failures - Rename fails when /tmp and workspace root are on different mounts Co-authored-by: Manuel Kießling <manuel@kiessling.net>
1 parent 000e900 commit 8ecad26

File tree

2 files changed

+68
-10
lines changed

2 files changed

+68
-10
lines changed

tests/Integration/WorkspaceMgmt/WorkspaceGitServiceTest.php

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,9 @@ private function createTestWorkspace(): Workspace
168168
$this->removeDirectory($targetPath);
169169
}
170170

171-
$renameResult = rename($this->testRepoPath, $targetPath);
172-
if (!$renameResult) {
173-
throw new \RuntimeException('Failed to rename ' . $this->testRepoPath . ' to ' . $targetPath);
174-
}
175-
171+
// Copy instead of rename (rename may fail across filesystems)
172+
$this->copyDirectory($this->testRepoPath, $targetPath);
173+
$this->removeDirectory($this->testRepoPath);
176174
$this->testRepoPath = $targetPath;
177175

178176
return $workspace;
@@ -186,6 +184,37 @@ private function runGitCommand(string $command): void
186184
$process->mustRun();
187185
}
188186

187+
private function copyDirectory(string $source, string $target): void
188+
{
189+
if (!is_dir($source)) {
190+
throw new \RuntimeException('Source directory does not exist: ' . $source);
191+
}
192+
193+
if (!is_dir($target)) {
194+
mkdir($target, 0777, true);
195+
}
196+
197+
$items = scandir($source);
198+
if ($items === false) {
199+
throw new \RuntimeException('Failed to scan source directory: ' . $source);
200+
}
201+
202+
foreach ($items as $item) {
203+
if ($item === '.' || $item === '..') {
204+
continue;
205+
}
206+
207+
$sourcePath = $source . '/' . $item;
208+
$targetPath = $target . '/' . $item;
209+
210+
if (is_dir($sourcePath)) {
211+
$this->copyDirectory($sourcePath, $targetPath);
212+
} else {
213+
copy($sourcePath, $targetPath);
214+
}
215+
}
216+
}
217+
189218
private function removeDirectory(string $path): void
190219
{
191220
if (!is_dir($path)) {

tests/Integration/WorkspaceMgmt/WorkspaceMgmtFacadeGitInfoTest.php

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,9 @@ private function createTestWorkspace(): Workspace
225225
$this->removeDirectory($targetPath);
226226
}
227227

228-
$renameResult = rename($this->testRepoPath, $targetPath);
229-
if (!$renameResult) {
230-
throw new \RuntimeException('Failed to rename ' . $this->testRepoPath . ' to ' . $targetPath);
231-
}
232-
228+
// Copy instead of rename (rename may fail across filesystems)
229+
$this->copyDirectory($this->testRepoPath, $targetPath);
230+
$this->removeDirectory($this->testRepoPath);
233231
$this->testRepoPath = $targetPath;
234232

235233
return $workspace;
@@ -243,6 +241,37 @@ private function runGitCommand(string $command): void
243241
$process->mustRun();
244242
}
245243

244+
private function copyDirectory(string $source, string $target): void
245+
{
246+
if (!is_dir($source)) {
247+
throw new \RuntimeException('Source directory does not exist: ' . $source);
248+
}
249+
250+
if (!is_dir($target)) {
251+
mkdir($target, 0777, true);
252+
}
253+
254+
$items = scandir($source);
255+
if ($items === false) {
256+
throw new \RuntimeException('Failed to scan source directory: ' . $source);
257+
}
258+
259+
foreach ($items as $item) {
260+
if ($item === '.' || $item === '..') {
261+
continue;
262+
}
263+
264+
$sourcePath = $source . '/' . $item;
265+
$targetPath = $target . '/' . $item;
266+
267+
if (is_dir($sourcePath)) {
268+
$this->copyDirectory($sourcePath, $targetPath);
269+
} else {
270+
copy($sourcePath, $targetPath);
271+
}
272+
}
273+
}
274+
246275
private function removeDirectory(string $path): void
247276
{
248277
if (!is_dir($path)) {

0 commit comments

Comments
 (0)