Repository navigation
Expand file tree
/
Copy pathe2eTestRunnerWithCache.php
More file actions
49 lines (38 loc) · 1.61 KB
/
Copy pathe2eTestRunnerWithCache.php
File metadata and controls
49 lines (38 loc) · 1.61 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
#!/usr/bin/env php
<?php
// runs a rector e2e test.
// checks whether we expect a certain output, or alternatively that rector just processed everything without errors
use Rector\Console\Formatter\ColorConsoleDiffFormatter;
use Rector\Console\Formatter\ConsoleDiffer;
use Rector\Console\Style\SymfonyStyleFactory;
use Rector\Differ\DefaultDiffer;
use Rector\Util\Reflection\PrivatesAccessor;
use Symfony\Component\Console\Command\Command;
$projectRoot = __DIR__ .'/..';
$rectorBin = $projectRoot . '/bin/rector';
$autoloadFile = $projectRoot . '/vendor/autoload.php';
// so we can use helper classes here
require_once __DIR__ . '/../vendor/autoload.php';
$e2eCommand = 'php '. $rectorBin .' process --dry-run --no-ansi -a '. $autoloadFile;
exec($e2eCommand, $output, $exitCode);
$output = trim(implode("\n", $output));
$output = str_replace(__DIR__, '.', $output);
$expectedDiff = 'expected-output.diff';
if (!file_exists($expectedDiff)) {
echo $output;
exit($exitCode);
}
$symfonyStyleFactory = new SymfonyStyleFactory(new PrivatesAccessor());
$symfonyStyle = $symfonyStyleFactory->create();
$matchedExpectedOutput = false;
$expectedOutput = trim((string) file_get_contents($expectedDiff));
if ($output === $expectedOutput) {
$symfonyStyle->success('End-to-end test successfully completed');
exit(Command::SUCCESS);
}
// print color diff, to make easy find the differences
$defaultDiffer = new DefaultDiffer();
$colorConsoleDiffFormatter = new ColorConsoleDiffFormatter();
$diff = $colorConsoleDiffFormatter->format($defaultDiffer->diff($output, $expectedOutput));
$symfonyStyle->writeln($diff);
exit(Command::FAILURE);