Skip to content

Commit 529ae1f

Browse files
milodg
authored andcommitted
Temporary directory preparation moved to Helpers
1 parent 76cf6a2 commit 529ae1f

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

src/Framework/Helpers.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,25 @@ public static function escapeArg(string $s): string
130130
? '"' . str_replace('"', '""', $s) . '"'
131131
: escapeshellarg($s);
132132
}
133+
134+
135+
/**
136+
* @internal
137+
*/
138+
public static function prepareTempDir(string $path): string
139+
{
140+
$real = realpath($path);
141+
if ($real === false) {
142+
throw new \RuntimeException("Path '$path' does not exist.");
143+
} elseif (!is_dir($real) || !is_writable($real)) {
144+
throw new \RuntimeException("Path '$real' is not a writable directory.");
145+
}
146+
147+
$path = $real . DIRECTORY_SEPARATOR . 'Tester';
148+
if (!is_dir($path) && @mkdir($path) === false && !is_dir($path)) { // @ - directory may exist
149+
throw new \RuntimeException("Cannot create '$path' directory.");
150+
}
151+
152+
return $path;
153+
}
133154
}

src/Runner/CliTester.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private function loadOptions(): CommandLine
134134
'-c' => [CommandLine::Realpath => true],
135135
'--watch' => [CommandLine::Repeatable => true, CommandLine::Realpath => true],
136136
'--setup' => [CommandLine::Realpath => true],
137-
'--temp' => [CommandLine::Realpath => true],
137+
'--temp' => [],
138138
'paths' => [CommandLine::Repeatable => true, CommandLine::Value => getcwd()],
139139
'--debug' => [],
140140
'--cider' => [],
@@ -181,8 +181,10 @@ private function loadOptions(): CommandLine
181181
} elseif (($real = realpath($temp)) === false) {
182182
echo "Note: System temporary directory '$temp' does not exist.\n";
183183
} else {
184-
$this->options['--temp'] = rtrim($real, DIRECTORY_SEPARATOR);
184+
$this->options['--temp'] = Helpers::prepareTempDir($real);
185185
}
186+
} else {
187+
$this->options['--temp'] = Helpers::prepareTempDir($this->options['--temp']);
186188
}
187189

188190
return $cmd;
@@ -220,10 +222,7 @@ private function createRunner(): Runner
220222
$runner->paths = $this->options['paths'];
221223
$runner->threadCount = max(1, (int) $this->options['-j']);
222224
$runner->stopOnFail = $this->options['--stop-on-fail'];
223-
224-
if ($this->options['--temp'] !== null) {
225-
$runner->setTempDirectory($this->options['--temp']);
226-
}
225+
$runner->setTempDirectory($this->options['--temp']);
227226

228227
if ($this->stdoutFormat === null) {
229228
$runner->outputHandlers[] = new Output\ConsolePrinter(

src/Runner/Runner.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,6 @@ public function addPhpIniOption(string $name, ?string $value = null): void
8484

8585
public function setTempDirectory(?string $path): void
8686
{
87-
if ($path !== null) {
88-
if (!is_dir($path) || !is_writable($path)) {
89-
throw new \RuntimeException("Path '$path' is not a writable directory.");
90-
}
91-
92-
$path = realpath($path) . DIRECTORY_SEPARATOR . 'Tester';
93-
if (!is_dir($path) && @mkdir($path) === false && !is_dir($path)) { // @ - directory may exist
94-
throw new \RuntimeException("Cannot create '$path' directory.");
95-
}
96-
}
97-
9887
$this->tempDir = $path;
9988
$this->testHandler->setTempDirectory($path);
10089
}

0 commit comments

Comments
 (0)