-
-
Notifications
You must be signed in to change notification settings - Fork 439
Expand file tree
/
Copy pathe2eTestRunner.php
More file actions
75 lines (57 loc) · 2.22 KB
/
e2eTestRunner.php
File metadata and controls
75 lines (57 loc) · 2.22 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
#!/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 . ' --clear-cache';
if (isset($argv[1]) && $argv[1] === '-c') {
$e2eCommand .= ' -c ' . $argv[2];
}
if (isset($argv[1]) && $argv[1] === '--config') {
$e2eCommand .= ' --config ' . $argv[2];
}
if (isset($argv[1]) && $argv[1] === '-a') {
$e2eCommand .= ' -a ' . $argv[2];
}
if (isset($argv[1]) && $argv[1] === '--no-diffs') {
$e2eCommand .= ' --no-diffs';
}
if (isset($argv[2]) && $argv[2] === '--output-format=json') {
$e2eCommand .= ' --output-format=json';
}
$cliOptions = 'cli-options.txt';
if (file_exists($cliOptions)) {
$e2eCommand .= ' ' . trim((string) file_get_contents($cliOptions));
}
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);