Skip to content

Commit cff3173

Browse files
committed
Make the parse error tests independent of when the result cache is rewritten
The run that breaks a file finds nothing to save and leaves the result cache as it was, and the next one rewrites it only when it can tell from the file's stat that it changed, which it cannot in the same second. Fixing the file back to its previous contents then re-analysed nothing sometimes, which is right, as the cache still describes those contents. The fixed file differs from them now. The first test asserts the re-analysed files with result-cache-info too. Amp-Thread-ID: https://ampcode.com/threads/T-01a1c5c8-8d5b-7459-a22c-beb8e7ba8a3b
1 parent ff3026c commit cff3173

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

‎e2e/result-cache-parse-error/result-cache-parse-error_test.sh‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ function test_result_cache_parse_error() {
2020
assert_contains 'Result cache is saved.' "$OUTPUT"
2121
test -f tmp/resultCache.php
2222
# Only src/Thing.php is analysed again, and the result cache is not rewritten.
23+
INFO=$(../../bin/phpstan result-cache-info --json)
24+
echo "$INFO"
25+
assert_equals 'true' "$(echo "$INFO" | jq --raw-output '.resultCacheUsed')"
26+
assert_equals '1' "$(echo "$INFO" | jq --raw-output '.filesToAnalyseCount')"
2327
OUTPUT=$(../../bin/phpstan analyse -vvv --error-format raw 2>&1) && CODE=0 || CODE=$?
2428
assert_same "1" "$CODE"
2529
echo "$OUTPUT"
2630
assert_contains 'Thing.php:12:Syntax error, unexpected EOF on line 12' "$OUTPUT"
27-
assert_contains 'Result cache restored. 1 file will be reanalysed.' "$OUTPUT"
2831
assert_contains 'Result cache was not rewritten because it is unchanged.' "$OUTPUT"
2932
# Fixing the parse error declares Thing, so the error that src/User.php had in the result
3033
# cache goes away.
@@ -58,8 +61,10 @@ function test_result_cache_parse_error_keeps_symbols() {
5861
echo "$INFO"
5962
assert_equals '1' "$(echo "$INFO" | jq --raw-output '.filesToAnalyseCount')"
6063
../../bin/phpstan analyse > /dev/null 2>&1 || true
61-
# Fixing it declares the same symbols as before it broke, so it is re-analysed alone too.
62-
cp fixed/Thing.php src/Thing.php
64+
# Fixing it declares the same symbols as before it broke, so it is re-analysed alone too. A
65+
# comment makes the file differ from what it was before it broke: the cache may still hold
66+
# that version, if no run had a reason to rewrite it, and then nothing is re-analysed.
67+
{ cat fixed/Thing.php; printf '\n// fixed\n'; } > src/Thing.php
6368
INFO=$(../../bin/phpstan result-cache-info --json)
6469
echo "$INFO"
6570
assert_equals '1' "$(echo "$INFO" | jq --raw-output '.filesToAnalyseCount')"

0 commit comments

Comments
 (0)