Skip to content

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Nov 6, 2019

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't sufficient. You need to also make sure that a message containing \r\n is ignored by ignoreErrors item that contains only \n. And to write an integration test in https://github.com/phpstan/phpstan-src/blob/master/tests/PHPStan/Command/ErrorFormatter/BaselineNeonErrorFormatterIntegrationTest.php that verifies everything actually works together.

@staabm
Copy link
Contributor Author

staabm commented Nov 9, 2019

Addded a unit test and fed data into the integration test, which failed for us in the real world app.

hopefully that what you requested.

@ondrejmirtes
Copy link
Member

We're still missing an integration test for BaselineNeonErrorFormatterIntegrationTest.php that would check that errors generated by a file with CRLF (that actually needs to be added to the repository) with baseline that generates only LF endings get also ignored.

@ondrejmirtes
Copy link
Member

Because the changes in IgnoredError.php still aren't tested.

@staabm
Copy link
Contributor Author

staabm commented Nov 9, 2019

We're still missing an integration test for BaselineNeonErrorFormatterIntegrationTest.php that would check that errors generated by a file with CRLF (that actually needs to be added to the repository) with baseline that generates only LF endings get also ignored.

I got the impression that the new method I added one one of the testclasses will generate a warning including a newline and therefore the lines should be covered?
(Since this classes are used to generate a baseline and re-apply the baseline to check whether all errors get ignored)

@ondrejmirtes
Copy link
Member

I think you need to add a new file that has CRLFs inside. I don't think that tests/PHPStan/Command/ErrorFormatter/data/Bar.php does.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved the test into this new file, which uses windows line endings.
also added a .gitattributes file, which should make sure that the line-endings for this file are enforced to CRLF

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 guess we need to change this assertion because of the newly added testfiles under data/

@ondrejmirtes
Copy link
Member

Hi, please make sure that your build passes locally running vendor/bin/phing before you push your changes. Looking at the diff, I think we're really close to merging this :)

@staabm
Copy link
Contributor Author

staabm commented Nov 10, 2019

Hi, please make sure that your build passes locally running vendor/bin/phing before you push your changes. Looking at the diff, I think we're really close to merging this :)

easier said, then done :-).

the tooling requires some non-standard php-extensions (e.g. ext-soap).
also the phing build/test-suite seem to not work on windows.. I am seeing some unrelated errors:

There were 8 failures: 1) PHPStan\Analyser\AnalyserIntegrationTest::testCollectWarnings Failed asserting that actual size 0 matches expected size 1. C:\xampp7.3\htdocs\phpstan-src\tests\PHPStan\Analyser\AnalyserIntegrationTest.php:189 2) PHPStan\Analyser\AnalyserTest::testIgnoreErrorByPathAndCountMoreThanExpected Failed asserting that two strings are identical. --- Expected +++ Actual @@ @@ -'C:\xampp7.3\htdocs\phpstan-src\tests\PHPStan\Analyser/data/two-fails.php' +'C:\xampp7.3\htdocs\phpstan-src\tests\PHPStan\Analyser\data\two-fails.php' C:\xampp7.3\htdocs\phpstan-src\tests\PHPStan\Analyser\AnalyserTest.php:100 3) PHPStan\Analyser\AnalyserTest::testIgnoreErrorByPathAndCountMissing Failed asserting that two strings are identical. --- Expected +++ Actual @@ @@ -'C:\xampp7.3\htdocs\phpstan-src\tests\PHPStan\Analyser/data/two-fails.php' +'C:\xampp7.3\htdocs\phpstan-src\tests\PHPStan\Analyser\data\two-fails.php' C:\xampp7.3\htdocs\phpstan-src\tests\PHPStan\Analyser\AnalyserTest.php:144 4) PHPStan\Command\CommandHelperTest::testResolveRelativePaths with data set #0 ('C:\xampp7.3\htdocs\phpstan-sr...t.neon', array('C:\xampp7.3\htdocs\phpstan-sr...re.php', array('C:\xampp7.3\htdocs\phpstan-sr...re.php', 'C:\xampp7.3\htdocs\phpstan-sr...re.php', 'C:\xampp7.3\htdocs\phpstan-sr...up.php'), array('C:\xampp7.3\htdocs\phpstan-sr...hs/src', 'C:\xampp7.3\htdocs\phpstan-sr...-paths', 'C:\xampp7.3\htdocs\phpstan-src\conf'), array('C:\xampp7.3\htdocs\phpstan-sr...hs/src'), 'C:\xampp7.3\htdocs\phpstan-sr..._limit', array('C:\xampp7.3\htdocs\phpstan-sr...hs/src'))) Failed asserting that two strings are identical. --- Expected +++ Actual @@ @@ -'C:\xampp7.3\htdocs\phpstan-src\tests\PHPStan\Command/relative-paths/here.php' +'C:\xampp7.3\htdocs\phpstan-src\tests\PHPStan\Command\relative-paths\here.php' C:\xampp7.3\htdocs\phpstan-src\tests\PHPStan\Command\CommandHelperTest.php:230 5) PHPStan\Command\CommandHelperTest::testResolveRelativePaths with data set #1 ('C:\xampp7.3\htdocs\phpstan-sr...d.neon', array(array('C:\xampp7.3\htdocs\phpstan-sr...re.php', 'C:\xampp7.3\htdocs\phpstan-sr...re.php', 'C:\xampp7.3\htdocs\phpstan-sr...up.php'), array(array('#aaa#', 'C:\xampp7.3\htdocs\phpstan-sr...aa.php'), array('#bbb#', array('C:\xampp7.3\htdocs\phpstan-sr...aa.php', 'C:\xampp7.3\htdocs\phpstan-sr...bb.php'))))) Failed asserting that two arrays are identical. --- Expected +++ Actual @@ @@ Array &0 ( - 0 => 'C:\xampp7.3\htdocs\phpstan-src\tests\PHPStan\Command/relative-paths/nested/here.php' - 1 => 'C:\xampp7.3\htdocs\phpstan-src\tests\PHPStan\Command/relative-paths/nested/test/there.php' - 2 => 'C:\xampp7.3\htdocs\phpstan-src\tests\PHPStan\Command/relative-paths/up.php' + 0 => 'C:\xampp7.3\htdocs\phpstan-src\tests\PHPStan\Command\relative-paths\nested\here.php' + 1 => 'C:\xampp7.3\htdocs\phpstan-src\tests\PHPStan\Command\relative-paths\nested\test\there.php' + 2 => 'C:\xampp7.3\htdocs\phpstan-src\tests\PHPStan\Command\relative-paths\up.php' ) C:\xampp7.3\htdocs\phpstan-src\tests\PHPStan\Command\CommandHelperTest.php:230 6) PHPStan\Node\FileNodeTest::testRule with data set #0 ('C:\xampp7.3\htdocs\phpstan-sr...ty.php', 'File empty.php is empty.', 1) Failed asserting that two strings are identical. --- Expected +++ Actual @@ @@ -'01: File empty.php is empty. +'01: File C:\xampp7.3\htdocs\phpstan-src\tests\PHPStan\Node\data\empty.php is empty. ' C:\xampp7.3\htdocs\phpstan-src\src\Testing\RuleTestCase.php:136 C:\xampp7.3\htdocs\phpstan-src\tests\PHPStan\Node\FileNodeTest.php:81 7) PHPStan\Node\FileNodeTest::testRule with data set #1 ('C:\xampp7.3\htdocs\phpstan-sr...re.php', 'First node in file declare.ph...clare_', 1) Failed asserting that two strings are identical. --- Expected +++ Actual @@ @@ -'01: First node in file declare.php is: PhpParser\Node\Stmt\Declare_ +'01: First node in file C:\xampp7.3\htdocs\phpstan-src\tests\PHPStan\Node\data\declare.php is: PhpParser\Node\Stmt\Declare_ ' C:\xampp7.3\htdocs\phpstan-src\src\Testing\RuleTestCase.php:136 C:\xampp7.3\htdocs\phpstan-src\tests\PHPStan\Node\FileNodeTest.php:81 8) PHPStan\Node\FileNodeTest::testRule with data set #2 ('C:\xampp7.3\htdocs\phpstan-sr...ce.php', 'First node in file namespace....space_', 3) Failed asserting that two strings are identical. --- Expected +++ Actual @@ @@ -'03: First node in file namespace.php is: PhpParser\Node\Stmt\Namespace_ +'03: First node in file C:\xampp7.3\htdocs\phpstan-src\tests\PHPStan\Node\data\namespace.php is: PhpParser\Node\Stmt\Namespace_ ' C:\xampp7.3\htdocs\phpstan-src\src\Testing\RuleTestCase.php:136 C:\xampp7.3\htdocs\phpstan-src\tests\PHPStan\Node\FileNodeTest.php:81 FAILURES! Tests: 4370, Assertions: 9637, Failures: 8, Skipped: 96. BUILD FAILED C:\xampp7.3\htdocs\phpstan-src\build.xml:195:3: Task exited with code 1 Total time: 11 minutes 35.09 seconds 

hopefully the travis build is finally green..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wdyt about moving this message-normalization into a single spot? does a class exists in which this would fit in well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine like this :)

@ondrejmirtes
Copy link
Member

Hi, it's still quite weird. The formatter still generates this baseline with the \r\n:

-	message: "#^PHPDoc tag @param has invalid value \\(\\)\\: Unexpected token \"\\\\r\\\\n\\\\t \\*\", expected TOKEN_IDENTIFIER at offset 113$#"	count: 1	path: tests/PHPStan/Command/ErrorFormatter/data/WindowsNewlines.php 

(I commented-out unlink in BaselineNeonErrorFormatterIntegrationTest and inspected baseline.neon in the root).

Also, if I comment out the preg_replace calls in IgnoredError.php, the tests still pass, which is weird. Can you investigate? Thanks.

@ondrejmirtes
Copy link
Member

^^ My theory is that your preg_replace calls do not work at all and it's still filtering based on \r\n in both the error message and the baseline file.

@ondrejmirtes
Copy link
Member

So baseline across platforms wouldn't work as expected.

@staabm
Copy link
Contributor Author

staabm commented Nov 12, 2019

^^ My theory is that your preg_replace calls do not work at all and it's still filtering based on \r\n in both the error message and the baseline file.

I dont get why those chars are already escaped.. but it seems thats something that happens in phpstan somewhere... tried to fix it with the recent commits..

not 100% sure whether its correct that a newline in a neon-formatted file is represented as \\\\n

@ondrejmirtes
Copy link
Member

It's a newline inside regex inside neon. But when you're replacing it, it's still clean and unescaped.

@ondrejmirtes
Copy link
Member

See: https://3v4l.org/Eeuch Your code didn't work...

@staabm
Copy link
Contributor Author

staabm commented Nov 12, 2019

See: https://3v4l.org/Eeuch Your code didn't work...

I expected the string to contain real newlines and work therefore like this:
https://3v4l.org/ORRkb

but nevertheless... :-)
it seems the build is green now.

@ondrejmirtes
Copy link
Member

That's not how the error messages work. I'll look into it, thanks.

@staabm
Copy link
Contributor Author

staabm commented Nov 16, 2019

@ondrejmirtes any chance to this into 0.12?
Or do you plan to check this PR after 0.12 was released?

@ondrejmirtes
Copy link
Member

I plan to include it in 0.12.

@ondrejmirtes
Copy link
Member

OK, I did a few more tests and realized:

  1. There's a bug in normalizing the $ignoredErrorPattern. See the fix: 1fe9d37#diff-cbca23e35d1037391be331873c46ca8dR54
  2. Normalizing in BaselineNeonErrorFormatter isn't necessary thanks to the fix in 1). fa4161a

Anyway, I just merged this. Thank you!

@staabm staabm deleted the patch-1 branch November 23, 2019 20:14
@staabm
Copy link
Contributor Author

staabm commented Nov 23, 2019

Thx for bringing it over the finish line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants