forked from rectorphp/rector-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathe2eTestChangingRunnerWithCache.php
More file actions
56 lines (43 loc) · 1.69 KB
/
e2eTestChangingRunnerWithCache.php
File metadata and controls
56 lines (43 loc) · 1.69 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
#!/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\Core\Console\Formatter\ColorConsoleDiffFormatter;
use Rector\Core\Console\Formatter\ConsoleDiffer;
use Rector\Core\Console\Style\SymfonyStyleFactory;
use Rector\Core\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 --no-ansi -a '. $autoloadFile;
if (isset($argv[1]) && $argv[1] === '-o') {
$expectedDiff = $argv[2];
} else {
$expectedDiff = 'expected-output.diff';
}
if (isset($argv[3]) && $argv[3] === '--dry-run') {
$e2eCommand .= ' --dry-run';
}
exec($e2eCommand, $output, $exitCode);
$output = trim(implode("\n", $output));
$output = str_replace(__DIR__, '.', $output);
if (!file_exists($expectedDiff)) {
echo $output;
exit($exitCode);
}
$symfonyStyleFactory = new SymfonyStyleFactory(new PrivatesAccessor());
$symfonyStyle = $symfonyStyleFactory->create();
$matchedExpectedOutput = false;
$expectedOutput = trim(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
$consoleDiffer = new ConsoleDiffer(new ColorConsoleDiffFormatter());
$diff = $consoleDiffer->diff($output, $expectedOutput);
$symfonyStyle->writeln($diff);
exit(Command::FAILURE);