-
Couldn't load subscription status.
- Fork 544
Fix inconsistent analysis on case-insensitive filesystems #3988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -308,7 +308,7 @@ jobs: | |
|
|
||
| e2e-tests: | ||
| name: "E2E tests" | ||
| runs-on: "ubuntu-latest" | ||
| runs-on: ${{ matrix.os }} | ||
| timeout-minutes: 60 | ||
|
|
||
| strategy: | ||
|
|
@@ -317,84 +317,127 @@ jobs: | |
| - script: "bin/phpstan analyse -l 8 -a tests/e2e/data/timecop.php -c tests/e2e/data/empty.neon tests/e2e/data/timecop.php" | ||
| tools: "pecl" | ||
| extensions: "timecop-beta" | ||
| os: "ubuntu-latest" | ||
| - script: "bin/phpstan analyse -l 8 -a tests/e2e/data/soap.php -c tests/e2e/data/empty.neon tests/e2e/data/soap.php" | ||
| extensions: "soap" | ||
| os: "ubuntu-latest" | ||
| - script: "bin/phpstan analyse -l 8 -a tests/e2e/data/soap.php -c tests/e2e/data/empty.neon tests/e2e/data/soap.php" | ||
| extensions: "" | ||
| os: "ubuntu-latest" | ||
| - script: "bin/phpstan analyse -l 8 tests/e2e/anon-class/Granularity.php" | ||
| extensions: "" | ||
| os: "ubuntu-latest" | ||
| - script: "bin/phpstan analyse -l 8 e2e/phpstan-phpunit-190/test.php -c e2e/phpstan-phpunit-190/test.neon" | ||
| extensions: "" | ||
| os: "ubuntu-latest" | ||
| - script: "bin/phpstan analyse e2e/only-files-not-analysed-trait/src -c e2e/only-files-not-analysed-trait/ignore.neon" | ||
| extensions: "" | ||
| os: "ubuntu-latest" | ||
| - script: "bin/phpstan analyse e2e/only-files-not-analysed-trait/src/Foo.php e2e/only-files-not-analysed-trait/src/BarTrait.php -c e2e/only-files-not-analysed-trait/no-ignore.neon" | ||
| extensions: "" | ||
| os: "ubuntu-latest" | ||
| - script: | | ||
| cd e2e/baseline-uninit-prop-trait | ||
| ../../bin/phpstan analyse --debug --configuration test-no-baseline.neon --generate-baseline test-baseline.neon | ||
| ../../bin/phpstan analyse --debug --configuration test.neon | ||
| os: "ubuntu-latest" | ||
| - script: | | ||
| cd e2e/baseline-uninit-prop-trait | ||
| ../../bin/phpstan analyse --configuration test-no-baseline.neon --generate-baseline test-baseline.neon | ||
| ../../bin/phpstan analyse --configuration test.neon | ||
| os: "ubuntu-latest" | ||
| - script: | | ||
| cd e2e/discussion-11362 | ||
| composer install | ||
| ../../bin/phpstan | ||
| os: "ubuntu-latest" | ||
| - script: | | ||
| cd e2e/bug-11819 | ||
| ../../bin/phpstan | ||
| os: "ubuntu-latest" | ||
| - script: | | ||
| cd e2e/composer-and-phpstan-version-config | ||
| composer install --ignore-platform-reqs | ||
| ../../bin/phpstan analyze test.php --level=0 | ||
| os: "ubuntu-latest" | ||
| - script: | | ||
| cd e2e/composer-max-version | ||
| composer install | ||
| ../../bin/phpstan analyze test.php --level=0 | ||
| os: "ubuntu-latest" | ||
| - script: | | ||
| cd e2e/composer-min-max-version | ||
| composer install | ||
| ../../bin/phpstan analyze test.php --level=0 | ||
| os: "ubuntu-latest" | ||
| - script: | | ||
| cd e2e/composer-min-open-end-version | ||
| composer install | ||
| ../../bin/phpstan analyze test.php --level=0 | ||
| os: "ubuntu-latest" | ||
| - script: | | ||
| cd e2e/composer-min-version-v5 | ||
| composer install --ignore-platform-reqs | ||
| ../../bin/phpstan analyze test.php --level=0 | ||
| os: "ubuntu-latest" | ||
| - script: | | ||
| cd e2e/composer-min-version-v7 | ||
| composer install --ignore-platform-reqs | ||
| ../../bin/phpstan analyze test.php --level=0 | ||
| os: "ubuntu-latest" | ||
| - script: | | ||
| cd e2e/composer-min-version | ||
| composer install | ||
| ../../bin/phpstan analyze test.php --level=0 | ||
| os: "ubuntu-latest" | ||
| - script: | | ||
| cd e2e/composer-no-versions | ||
| composer install | ||
| ../../bin/phpstan analyze test.php --level=0 | ||
| os: "ubuntu-latest" | ||
| - script: | | ||
| cd e2e/composer-version-config-invalid | ||
| OUTPUT=$(../bashunit -a exit_code "1" ../../bin/phpstan) | ||
| echo "$OUTPUT" | ||
| ../bashunit -a contains 'Invalid configuration' "$OUTPUT" | ||
| ../bashunit -a contains 'Invalid PHP version range: phpVersion.max should be greater or equal to phpVersion.min.' "$OUTPUT" | ||
| os: "ubuntu-latest" | ||
| - script: | | ||
| cd e2e/composer-version-config-patch | ||
| composer install --ignore-platform-reqs | ||
| ../../bin/phpstan analyze test.php --level=0 | ||
| os: "ubuntu-latest" | ||
| - script: | | ||
| cd e2e/composer-version-config | ||
| composer install | ||
| ../../bin/phpstan analyze test.php --level=0 | ||
| os: "ubuntu-latest" | ||
| - script: | | ||
| cd e2e/bug-12972 | ||
| OUTPUT=$(../bashunit -a exit_code "1" ../../bin/phpstan) | ||
| echo "$OUTPUT" | ||
| ../bashunit -a contains 'Internal error: Failed opening required' "$OUTPUT" | ||
| ../bashunit -a contains 'e2e/bug-12972/src/OTHER/file.php' "$OUTPUT" | ||
| os: "ubuntu-latest" | ||
| - script: | | ||
| cd e2e/bug-12972 | ||
| ../../bin/phpstan analyze | ||
| os: "macos-latest" | ||
| - script: | | ||
| cd e2e/bug-12972 | ||
| ../../bin/phpstan analyze | ||
| os: "windows-latest" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't get it. Why do you expect different outcomes on Linux vs. the rest? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because linux does not have a case-insensitive filesystem. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So you have a project that deliberately works only on case-insensitive filesystems? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the test mimics what php-src will do at runtime. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like if the e2e test mimiced how your project actually worked. This just looks like PHPStan fixes macOS but breaks Linux. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, lets look into #4003 which mimics our project setup more closely |
||
|
|
||
| steps: | ||
| - name: "Checkout" | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: "Install GNU Patch on macOS" # see https://github.com/cweagans/composer-patches/issues/326 | ||
| if: runner.os == 'macOS' | ||
| run: | | ||
| brew install gpatch | ||
| echo "/opt/homebrew/opt/gpatch/libexec/gnubin" >> $GITHUB_PATH | ||
|
|
||
|
Comment on lines
+435
to
+440
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. on macOS we need a GNU compatible |
||
| - name: "Install PHP" | ||
| uses: "shivammathur/setup-php@v2" | ||
| with: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <?php | ||
|
|
||
| spl_autoload_register(function($class) { | ||
| if ($class === \other12972\MyClass::class) { | ||
| require_once __DIR__ . '/src/OTHER/file.php'; // wrong case sensitivity on purpose | ||
| } | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| parameters: | ||
| level: 9 | ||
|
|
||
| paths: | ||
| - src | ||
|
|
||
| bootstrapFiles: | ||
| - autoloader.php |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <?php | ||
|
|
||
| namespace Foo12972; | ||
|
|
||
| use other12972\MyClass; | ||
|
|
||
| function doBar(MyClass $myClass):void {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <?php | ||
|
|
||
| namespace other12972; | ||
|
|
||
| class MyClass { | ||
| public function doSomething(): int | ||
| { | ||
| return 1; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace PHPStan\Analyser; | ||
|
|
||
| use PHPStan\File\FilesystemHelper; | ||
| use function array_fill_keys; | ||
| use function array_map; | ||
| use function strtolower; | ||
|
|
||
| final class AnalysedFilesResolver | ||
| { | ||
|
|
||
| /** @var bool[] filePath(string) => bool(true) */ | ||
| private array $analysedFiles; | ||
|
|
||
| /** | ||
| * @param string[] $files | ||
| */ | ||
| public function __construct(array $files = []) | ||
| { | ||
| $this->setAnalysedFiles($files); | ||
| } | ||
|
|
||
| /** | ||
| * @param string[] $files | ||
| */ | ||
| public function setAnalysedFiles(array $files): void | ||
| { | ||
| if (FilesystemHelper::isCaseSensitive() === false) { | ||
| $files = array_map(static fn (string $file): string => strtolower($file), $files); | ||
| } | ||
| $this->analysedFiles = array_fill_keys($files, true); | ||
| } | ||
|
|
||
| public function isInAnalyzedFiles(string $file): bool | ||
| { | ||
| if (FilesystemHelper::isCaseSensitive() === false) { | ||
| $file = strtolower($file); | ||
| } | ||
|
|
||
| return isset($this->analysedFiles[$file]); | ||
| } | ||
|
|
||
| } |