-
Notifications
You must be signed in to change notification settings - Fork 510
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
Open
staabm
wants to merge
1
commit into
phpstan:2.1.x
Choose a base branch
from
staabm:bug12972
base: 2.1.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+186
−54
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
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: | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
parameters: | ||
level: 9 | ||
|
||
paths: | ||
- src | ||
|
||
bootstrapFiles: | ||
- autoloader.php |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
the test mimics what php-src will do at runtime.
it will happily accept a different-cased path on windows/macos but doesn't on linux (acutally depending on the filesystem case-sensitivy not the OS itself).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.