Skip to content
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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/PhpDoc/StubValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function validate(): array
$errors = [];
foreach ($this->stubFiles as $stubFile) {
$tmpErrors = $fileAnalyser->analyseFile(
$stubFile,
str_replace(DIRECTORY_SEPARATOR, '/', $stubFile),
Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Member

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.)

Copy link
Contributor Author

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

Copy link
Contributor Author

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?

$ruleRegistry,
static function (): void {
}
Expand Down
2 changes: 1 addition & 1 deletion src/Testing/LevelsTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testLevels(
string $topic
): void
{
$file = sprintf('%s/%s.php', $this->getDataPath(), $topic);
$file = sprintf('%s' . DIRECTORY_SEPARATOR . '%s.php', $this->getDataPath(), $topic);
$command = escapeshellcmd($this->getPhpStanExecutablePath());
$configPath = $this->getPhpStanConfigPath();
$fileHelper = new FileHelper(__DIR__ . '/../..');
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/AnalyserIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public function testCollectWarnings(): void
$errors = $this->runAnalyse(__DIR__ . '/data/declaration-warning.php');
$this->assertCount(1, $errors);
$this->assertSame('Declaration of DeclarationWarning\Bar::doFoo(int $i): void should be compatible with DeclarationWarning\Foo::doFoo(): void', $errors[0]->getMessage());
$this->assertSame(__DIR__ . '/data/declaration-warning.php', $errors[0]->getFile());
$this->assertSame(__DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'declaration-warning.php', $errors[0]->getFile());
$this->assertSame(PHP_VERSION_ID >= 70400 ? 22 : 27, $errors[0]->getLine());
}

Expand Down
34 changes: 17 additions & 17 deletions tests/PHPStan/Command/CommandHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,24 +160,24 @@ public function dataResolveRelativePaths(): array
[
__DIR__ . '/relative-paths/root.neon',
[
'bootstrap' => __DIR__ . '/relative-paths/here.php',
'bootstrap' => __DIR__ . DIRECTORY_SEPARATOR . 'relative-paths' . DIRECTORY_SEPARATOR . 'here.php',
'autoload_files' => [
__DIR__ . '/relative-paths/here.php',
__DIR__ . '/relative-paths/test/there.php',
__DIR__ . '/up.php',
__DIR__ . DIRECTORY_SEPARATOR . 'relative-paths' . DIRECTORY_SEPARATOR . 'here.php',
__DIR__ . DIRECTORY_SEPARATOR . 'relative-paths' . DIRECTORY_SEPARATOR . 'test' . DIRECTORY_SEPARATOR . 'there.php',
__DIR__ . DIRECTORY_SEPARATOR . 'up.php',
],
'autoload_directories' => [
__DIR__ . '/relative-paths/src',
__DIR__ . '/relative-paths',
realpath(__DIR__ . '/../../../conf'),
__DIR__ . DIRECTORY_SEPARATOR . 'relative-paths' . DIRECTORY_SEPARATOR . 'src',
__DIR__ . DIRECTORY_SEPARATOR . 'relative-paths',
realpath(__DIR__ . '/../../../') . '/conf',
],
'paths' => [
__DIR__ . '/relative-paths/src',
__DIR__ . DIRECTORY_SEPARATOR . 'relative-paths' . DIRECTORY_SEPARATOR . 'src',
],
'memoryLimitFile' => __DIR__ . '/relative-paths/.memory_limit',
'memoryLimitFile' => __DIR__ . DIRECTORY_SEPARATOR . 'relative-paths' . DIRECTORY_SEPARATOR . '.memory_limit',
'excludes_analyse' => [
__DIR__ . '/relative-paths/src',
__DIR__ . '/relative-paths/src/*/data',
__DIR__ . DIRECTORY_SEPARATOR . 'relative-paths' . DIRECTORY_SEPARATOR . 'src',
__DIR__ . DIRECTORY_SEPARATOR . 'relative-paths' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR . 'data',
'*/src/*/data',
],
],
Expand All @@ -186,20 +186,20 @@ public function dataResolveRelativePaths(): array
__DIR__ . '/relative-paths/nested/nested.neon',
[
'autoload_files' => [
__DIR__ . '/relative-paths/nested/here.php',
__DIR__ . '/relative-paths/nested/test/there.php',
__DIR__ . '/relative-paths/up.php',
__DIR__ . DIRECTORY_SEPARATOR . 'relative-paths' . DIRECTORY_SEPARATOR . 'nested' . DIRECTORY_SEPARATOR . 'here.php',
__DIR__ . DIRECTORY_SEPARATOR . 'relative-paths' . DIRECTORY_SEPARATOR . 'nested' . DIRECTORY_SEPARATOR . 'test' . DIRECTORY_SEPARATOR . 'there.php',
__DIR__ . DIRECTORY_SEPARATOR . 'relative-paths' . DIRECTORY_SEPARATOR . 'up.php',
],
'ignoreErrors' => [
[
'message' => '#aaa#',
'path' => __DIR__ . '/relative-paths/nested/src/aaa.php',
'path' => __DIR__ . DIRECTORY_SEPARATOR . 'relative-paths' . DIRECTORY_SEPARATOR . 'nested' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'aaa.php',
],
[
'message' => '#bbb#',
'paths' => [
__DIR__ . '/relative-paths/src/aaa.php',
__DIR__ . '/relative-paths/nested/src/bbb.php',
__DIR__ . DIRECTORY_SEPARATOR . 'relative-paths' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'aaa.php',
__DIR__ . DIRECTORY_SEPARATOR . 'relative-paths' . DIRECTORY_SEPARATOR . 'nested' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'bbb.php',
],
],
],
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Node/FileNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function getNodeType(): string
public function processNode(Node $node, Scope $scope): array
{
$nodes = $node->getNodes();
$pathHelper = new SimpleRelativePathHelper(__DIR__ . '/data');
$pathHelper = new SimpleRelativePathHelper(__DIR__ . DIRECTORY_SEPARATOR . 'data');
if (!isset($nodes[0])) {
return [
RuleErrorBuilder::message(sprintf('File %s is empty.', $pathHelper->getRelativePath($scope->getFile())))->line(1)->build(),
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function testRule(): void
70,
],
[
'Parameter #1 $str of callable class@anonymous/tests/PHPStan/Rules/Functions/data/callables.php:75 expects string, int given.',
'Parameter #1 $str of callable class@anonymous/tests' . DIRECTORY_SEPARATOR . 'PHPStan' . DIRECTORY_SEPARATOR . 'Rules' . DIRECTORY_SEPARATOR . 'Functions' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'callables.php:75 expects string, int given.',
81,
],
[
Expand Down