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
fix windows tests #74
Conversation
src/PhpDoc/StubValidator.php
Outdated
@@ -82,7 +82,7 @@ public function validate(): array | |||
$errors = []; | |||
foreach ($this->stubFiles as $stubFile) { | |||
$tmpErrors = $fileAnalyser->analyseFile( | |||
$stubFile, | |||
str_replace(DIRECTORY_SEPARATOR, '/', $stubFile), |
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 have a doubt on this one. While the PHPStan\Levels\StubValidatorIntegrationTest Test pass multiple times in a row, I think another test is deleting the "stubValidator-0.json" file.
If I'm not mistaken, the tests pass on the first try, but on the second, it complains about the file missing. However, I couldn't fix the issue without that
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 tests extending LevelsTestCase are self-updating - if the expected contents of JSON files do not match, they are updated and the test fails. When running the 2nd time on the updated JSON files, the test will pass. So this change is breaking something if the JSON files are getting updated.
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 think this change should be here, only test asserts should be updated.)
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.
Yeah, I noticed that, when the test failed on first try, they passed on the second. What's weird this time is that the test pass on first try but fail after. I will investigate more on this
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 think this change should be here, only test asserts should be updated.)
You're right, only the tests should change. I'll revert this line.
But to fix the actual issue, I'm kinda stuck. On LevelsTestCase::testLevels we use exec() to launch phpstan. This will always return Windows style path on Windows. And later, we compare this to a file generated on linux.
So we have to translate a path from one style to another somehow. Unfortunately, the FileHelper class use the DIRECTORY_SEPARATOR and will always normalize path on the same style.
This means we have to create a function to normalize a path with the opposite style. (To summarize, transform a Windows path to a Linux path) and then convert all the path in the phpstan output. Do you agree with that?
@@ -2,6 +2,9 @@ os: linux | |||
dist: xenial | |||
language: php | |||
|
|||
git: | |||
autocrlf: false |
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 had similar issues running the tests locally on windows. It would be great to have a solution which will not only work on travis.
Does #50 Work for your problem?
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 had similar issues with other repos as well, that's why my autocrlf setting on windows is set to false by default. It works very well locally too.
I believe it's possible to configure this on a project basis. Based on what I've experienced, I'd recommend setting this to false by default and switching it back(to input or true) on projects that must absolutely have CRLF.
#50 should work too, I just didn't needed it locally so I put the same setting on travis.
While working on phpstan/phpstan/issues/2784, I needed to get the tests working on windows.
Not sure it's always fixed the best way possible and maybe you don't care about the tests on windows, but now that it's done, I can at least create the PR!