Repository navigation
Expand file tree
/
Copy pathAdapterTestCase.php
More file actions
56 lines (47 loc) · 1.7 KB
/
Copy pathAdapterTestCase.php
File metadata and controls
56 lines (47 loc) · 1.7 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
<?php
namespace Phpactor\CodeTransform\Tests\Adapter;
use Phpactor\CodeBuilder\Adapter\Twig\TwigRenderer;
use Phpactor\CodeBuilder\Adapter\TolerantParser\TolerantUpdater;
use PHPUnit\Framework\TestCase;
use Phpactor\CodeTransform\Domain\Macro\Macro;
use Phpactor\CodeTransform\Domain\Macro\MacroRegistry;
use Phpactor\CodeTransform\Domain\Macro\MacroRunner;
use Phpactor\CodeTransform\Domain\SourceCode;
use Phpactor\TestUtils\Workspace;
use Phpactor\TestUtils\ExtractOffset;
class AdapterTestCase extends TestCase
{
protected function executeMacro(Macro $macro, array $arguments): SourceCode
{
$macroRegistry = new MacroRegistry([$macro]);
$macroRunner = new MacroRunner($macroRegistry);
return $macroRunner->run($macro->name(), $arguments);
}
protected function renderer()
{
return new TwigRenderer();
}
protected function updater()
{
return new TolerantUpdater($this->renderer());
}
protected function workspace(): Workspace
{
return Workspace::create(__DIR__ . '/../Workspace');
}
protected function sourceExpected($manifestPath)
{
$workspace = $this->workspace();
$workspace->reset();
$workspace->loadManifest(file_get_contents($manifestPath));
$source = $workspace->getContents('source');
$expected = $workspace->getContents('expected');
return [ $source, $expected ];
}
protected function sourceExpectedAndOffset($manifestPath)
{
list($source, $expected) = $this->sourceExpected($manifestPath);
list($source, $offsetStart, $offsetEnd) = ExtractOffset::fromSource($source);
return [ $source, $expected, $offsetStart, $offsetEnd ];
}
}