-
-
Notifications
You must be signed in to change notification settings - Fork 154
Expand file tree
/
Copy pathIntegrationTestCase.php
More file actions
109 lines (92 loc) · 2.92 KB
/
IntegrationTestCase.php
File metadata and controls
109 lines (92 loc) · 2.92 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
namespace Phpactor\Tests;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Process\Process;
use Symfony\Component\Filesystem\Filesystem;
use PHPUnit\Framework\TestCase;
use Phpactor\TestUtils\Workspace;
use Symfony\Component\Console\Input\ArrayInput;
use Phpactor\Container\Container;
use Phpactor\Phpactor;
abstract class IntegrationTestCase extends TestCase
{
/**
* @param list<string> $cmd
*/
public function phpactor(array $cmd): Process
{
$p = new Process(array_merge(
[PHP_BINARY, __DIR__ . '/../bin/phpactor'],
$cmd
), $this->workspace()->path());
return $p;
}
protected function workspaceDir(): string
{
return __DIR__ . '/Assets/Workspace';
}
protected function workspace(): Workspace
{
return Workspace::create($this->workspaceDir());
}
protected function assertSuccess(Process $process): void
{
if (true === $process->isSuccessful()) {
$this->addToAssertionCount(1);
return;
}
$this->fail(sprintf(
'Process exited with code %d: %s %s',
$process->getExitCode(),
$process->getErrorOutput(),
$process->getOutput()
));
}
protected function assertFailure(Process $process, ?string $message): void
{
if (true === $process->isSuccessful()) {
$this->fail('Process was a success');
}
if (null !== $message) {
$this->assertStringContainsString($message, $process->getErrorOutput());
}
$this->addToAssertionCount(1);
}
protected function loadProject(string $name): void
{
$filesystem = new Filesystem();
if (file_exists($this->cacheDir($name))) {
$filesystem->mirror($this->cacheDir($name), $this->workspaceDir());
return;
}
$filesystem->mirror(__DIR__ . '/Assets/Projects/' . $name, $this->workspaceDir());
$currentDir = getcwd();
chdir($this->workspaceDir());
exec('git init');
exec('git add *');
exec('git commit -m "Test"');
exec('composer install --quiet');
chdir($currentDir);
$this->cacheWorkspace($name);
}
protected function container(): Container
{
return Phpactor::boot(new ArrayInput([
'--working-dir' => $this->workspaceDir(),
]), new BufferedOutput(), __DIR__ . '/../vendor');
}
private function cacheDir(string $name): string
{
return __DIR__ . '/Assets/Cache/'.$name;
}
private function cacheWorkspace(string $name): void
{
$filesystem = new Filesystem();
$cacheDir = $this->cacheDir($name);
if (file_exists($cacheDir)) {
$filesystem->remove($cacheDir);
}
mkdir($cacheDir, 0777, true);
$filesystem->mirror($this->workspaceDir(), $this->cacheDir($name));
}
}