-
-
Notifications
You must be signed in to change notification settings - Fork 440
Expand file tree
/
Copy pathe2eTestRunnerCacheInvalidation.php
More file actions
66 lines (48 loc) · 2.36 KB
/
e2eTestRunnerCacheInvalidation.php
File metadata and controls
66 lines (48 loc) · 2.36 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
#!/usr/bin/env php
<?php
// Tests that CacheMetaExtensionInterface invalidates cache when the hash changes.
//
// Step 1: Run Rector with enabled.txt=false and --clear-cache → no changes, cache populated
// Step 2: Change enabled.txt to true → cache invalidated → rule triggers → changes reported
use Rector\Console\Formatter\ColorConsoleDiffFormatter;
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';
require_once __DIR__ . '/../../vendor/autoload.php';
$symfonyStyleFactory = new SymfonyStyleFactory(new PrivatesAccessor());
$symfonyStyle = $symfonyStyleFactory->create();
$e2eCommand = 'php '. $rectorBin .' process --dry-run --no-ansi -a '. $autoloadFile;
// Step 1: enabled=false, clear cache → no changes
file_put_contents(__DIR__ . '/enabled.txt', "false\n");
$output = [];
exec($e2eCommand . ' --clear-cache', $output, $exitCode);
$outputString = trim(implode("\n", $output));
if (! str_contains($outputString, '[OK] Rector is done!')) {
$symfonyStyle->error('Step 1 failed: Expected no changes with enabled=false');
$symfonyStyle->writeln($outputString);
exit(Command::FAILURE);
}
$symfonyStyle->success('Step 1 passed: No changes with enabled=false');
// Step 2: enabled=true, no --clear-cache → cache meta invalidated → rule triggers
file_put_contents(__DIR__ . '/enabled.txt', "true\n");
$output = [];
exec($e2eCommand, $output, $exitCode);
$outputString = trim(implode("\n", $output));
$outputString = str_replace(__DIR__, '.', $outputString);
$expectedOutput = trim((string) file_get_contents(__DIR__ . '/expected-output.diff'));
// Restore enabled.txt
file_put_contents(__DIR__ . '/enabled.txt', "false\n");
if ($outputString === $expectedOutput) {
$symfonyStyle->success('Step 2 passed: Cache invalidated, rule triggered');
exit(Command::SUCCESS);
}
$symfonyStyle->error('Step 2 failed: Expected cache invalidation to trigger the rule');
$defaultDiffer = new DefaultDiffer();
$colorConsoleDiffFormatter = new ColorConsoleDiffFormatter();
$diff = $colorConsoleDiffFormatter->format($defaultDiffer->diff($outputString, $expectedOutput));
$symfonyStyle->writeln($diff);
exit(Command::FAILURE);