phpstan / phpstan

PHP Static Analysis Tool - discover bugs in your code without running it!
https://phpstan.org/
MIT License
12.86k stars 870 forks source link

Strange error with file_get_contents + is_string check #1359

Closed Jean85 closed 6 years ago

Jean85 commented 6 years ago

Summary of a problem or a feature request

I'm using PHPStan 0.10.3. I have a small helper method in my base test case to fetch file contents without upsetting the PHPStan analysis. If I write the helper method in the first way (testMethodOne in the code snippet) it gets flagged, if I reverse the boolean logic of the guard (testMethodTwo), it's fine. It should be fine either way!

Code snippet that reproduces the problem

https://phpstan.org/r/23fff8faf435e4b9f6561c5857c1b2e2

Expected output

No errors.

ondrejmirtes commented 6 years ago

Do you have BaseTestCase::fail in early terminathing method calls? Check out https://github.com/phpstan/phpstan#custom-early-terminating-method-calls.

Jean85 commented 6 years ago

I'm using PHPUnit\Framework\TestCase::fail(), I didn't implement myself; I've just copied the implementation inside the code snippet, apart from the fact that I replaced the exception with a generic one, the original method uses PHPUnit\Framework\AssertionFailedError.

That would be a nice workaround, but I think it should be on this lib to do that normally.

ondrejmirtes commented 6 years ago

Yeah, I was giving you advice based on the snippet you posted 😊

The config is there if you install the extension: https://github.com/phpstan/phpstan-phpunit/blob/master/extension.neon#L4

Jean85 commented 6 years ago

Wops, my bad, I forgot to require the configuration! Sorry for wasting your time.