-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorkspaceFactory.php
More file actions
64 lines (50 loc) · 1.8 KB
/
Copy pathWorkspaceFactory.php
File metadata and controls
64 lines (50 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
declare(strict_types=1);
namespace Greph\Tests\Oracle;
use Greph\Support\CommandRunner;
use Greph\Support\Filesystem;
use Greph\Tests\Support\Workspace;
final class WorkspaceFactory
{
private CommandRunner $commandRunner;
public function __construct(?CommandRunner $commandRunner = null)
{
$this->commandRunner = $commandRunner ?? new CommandRunner();
}
public function create(Scenario $scenario, string $prefix): string
{
$workspaceRoot = Workspace::createDirectory($prefix);
Filesystem::ensureDirectory($workspaceRoot);
if (is_dir($scenario->setupDir())) {
Workspace::copyDirectory($scenario->setupDir(), $workspaceRoot . '/setup');
}
if (is_file($scenario->setupScriptPath())) {
$process = $this->commandRunner->run(
['bash', $scenario->setupScriptPath()],
$workspaceRoot,
['GREPH_ROOT' => $scenario->rootPath],
);
if (!$process->successful()) {
throw new \RuntimeException(sprintf(
'Setup script failed for %s: %s',
$scenario->name,
$process->output(),
));
}
}
$this->ensureGitMarkers($scenario, $workspaceRoot);
return $workspaceRoot;
}
private function ensureGitMarkers(Scenario $scenario, string $workspaceRoot): void
{
foreach ($scenario->paths() as $path) {
$searchRoot = $workspaceRoot . '/' . ltrim($path, '/');
if (!is_dir($searchRoot)) {
continue;
}
if (is_file($searchRoot . '/.gitignore') && !is_dir($searchRoot . '/.git')) {
Filesystem::ensureDirectory($searchRoot . '/.git');
}
}
}
}