|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +function set_up() { |
| 4 | + e2e::set_up |
| 5 | +} |
| 6 | + |
| 7 | +function tear_down() { |
| 8 | + e2e::tear_down |
| 9 | +} |
| 10 | + |
| 11 | +function test_whole_project_reports_all_unmatched_ignores() { |
| 12 | + OUTPUT=$(../../bin/phpstan analyse --error-format raw 2>&1) && CODE=0 || CODE=$? |
| 13 | + echo "$OUTPUT" |
| 14 | + assert_same "1" "$CODE" |
| 15 | + assert_contains '#never in Clean# in path' "$OUTPUT" |
| 16 | + assert_contains '#never in srcc# in path' "$OUTPUT" |
| 17 | + assert_contains '#never in Plain directory# in path' "$OUTPUT" |
| 18 | + assert_contains '#never in srcc directory# in path' "$OUTPUT" |
| 19 | + assert_contains '#never in Plain glob# in path' "$OUTPUT" |
| 20 | + assert_contains '#never in src glob# in path' "$OUTPUT" |
| 21 | + assert_contains '#never in leading glob# in path' "$OUTPUT" |
| 22 | + assert_contains '#never in two paths# in paths:' "$OUTPUT" |
| 23 | + assert_contains 'Ignored error pattern #never globally# was not matched' "$OUTPUT" |
| 24 | + assert_contains 'Ignored error pattern #never globally either# was not matched' "$OUTPUT" |
| 25 | + assert_contains 'is expected to occur 2 times, but occurred only 1 time.' "$OUTPUT" |
| 26 | +} |
| 27 | + |
| 28 | +function test_cli_paths_covering_config_paths_are_the_whole_project() { |
| 29 | + OUTPUT=$(../../bin/phpstan analyse --error-format raw src srcc tests 2>&1) && CODE=0 || CODE=$? |
| 30 | + echo "$OUTPUT" |
| 31 | + assert_same "1" "$CODE" |
| 32 | + assert_contains '#never in srcc directory# in path' "$OUTPUT" |
| 33 | + assert_contains '#never in leading glob# in path' "$OUTPUT" |
| 34 | + assert_contains 'Ignored error pattern #never globally# was not matched' "$OUTPUT" |
| 35 | +} |
| 36 | + |
| 37 | +function test_subdirectory_reports_only_ignores_under_it() { |
| 38 | + OUTPUT=$(../../bin/phpstan analyse --error-format raw src 2>&1) && CODE=0 || CODE=$? |
| 39 | + echo "$OUTPUT" |
| 40 | + assert_same "1" "$CODE" |
| 41 | + assert_contains '#never in Clean# in path' "$OUTPUT" |
| 42 | + assert_contains '#never in Plain directory# in path' "$OUTPUT" |
| 43 | + assert_contains '#never in Plain glob# in path' "$OUTPUT" |
| 44 | + assert_contains '#never in src glob# in path' "$OUTPUT" |
| 45 | + assert_contains 'is expected to occur 2 times, but occurred only 1 time.' "$OUTPUT" |
| 46 | + # only the path under the analysed paths is left in the entry |
| 47 | + assert_contains "#never in two paths# in path $PWD/src/Plain/Clean.php was not matched" "$OUTPUT" |
| 48 | + # srcc/ starts with src, but it is not under src/ |
| 49 | + assert_not_contains '#never in srcc#' "$OUTPUT" |
| 50 | + assert_not_contains '#never in srcc directory#' "$OUTPUT" |
| 51 | + # a pattern starting with a wildcard can match anywhere |
| 52 | + assert_not_contains '#never in leading glob#' "$OUTPUT" |
| 53 | + # what an entry without a path matches can be anywhere |
| 54 | + assert_not_contains '#never globally#' "$OUTPUT" |
| 55 | + assert_not_contains '#never globally either#' "$OUTPUT" |
| 56 | +} |
| 57 | + |
| 58 | +function test_deeper_subdirectory() { |
| 59 | + OUTPUT=$(../../bin/phpstan analyse --error-format raw src/Plain 2>&1) && CODE=0 || CODE=$? |
| 60 | + echo "$OUTPUT" |
| 61 | + assert_same "1" "$CODE" |
| 62 | + assert_contains '#never in Clean# in path' "$OUTPUT" |
| 63 | + assert_contains '#never in Plain directory# in path' "$OUTPUT" |
| 64 | + assert_contains '#never in Plain glob# in path' "$OUTPUT" |
| 65 | + # src/*/Clean.php can match files in other directories under src/ |
| 66 | + assert_not_contains '#never in src glob#' "$OUTPUT" |
| 67 | + assert_not_contains '#never globally#' "$OUTPUT" |
| 68 | +} |
| 69 | + |
| 70 | +function test_sibling_directory() { |
| 71 | + OUTPUT=$(../../bin/phpstan analyse --error-format raw srcc 2>&1) && CODE=0 || CODE=$? |
| 72 | + echo "$OUTPUT" |
| 73 | + assert_same "1" "$CODE" |
| 74 | + assert_contains '#never in srcc# in path' "$OUTPUT" |
| 75 | + assert_contains '#never in srcc directory# in path' "$OUTPUT" |
| 76 | + assert_contains "#never in two paths# in path $PWD/srcc/Bar.php was not matched" "$OUTPUT" |
| 77 | + assert_not_contains '#never in Clean#' "$OUTPUT" |
| 78 | + assert_not_contains '#never in Plain directory#' "$OUTPUT" |
| 79 | + assert_not_contains '#never in Plain glob#' "$OUTPUT" |
| 80 | + assert_not_contains '#never in src glob#' "$OUTPUT" |
| 81 | + assert_not_contains 'is expected to occur' "$OUTPUT" |
| 82 | + assert_not_contains '#never globally#' "$OUTPUT" |
| 83 | +} |
| 84 | + |
| 85 | +function test_directory_without_ignores() { |
| 86 | + OUTPUT=$(../../bin/phpstan analyse --error-format raw tests 2>&1) && CODE=0 || CODE=$? |
| 87 | + echo "$OUTPUT" |
| 88 | + assert_same "0" "$CODE" |
| 89 | +} |
0 commit comments