-
Notifications
You must be signed in to change notification settings - Fork 523
Lazy assert types gathering in TypeInferenceTestCase
#1991
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
Lazy assert types gathering in TypeInferenceTestCase
#1991
Conversation
d9ed9db
to
1d87bff
Compare
I think something like this has been proposed before but the main blocker for me is that only the first failure from a file is reported, not all of them. That's why it's currently done with generators like that. |
oh, you're right, yes. I also noticed that when fixing the test files where assertType was not working. that is kind of a deal-breaker I guess hmm :/ |
1d87bff
to
864c707
Compare
I re-implemented the assertion part, in the simplest way I could currently imagine, to only fail once per file basically => output all errors in a file at once. I like the output even more than before tbh, because it's more compact, e.g.: There were 2 failures:
1) PHPStan\Analyser\NodeScopeResolverTest::testAssertions with data set "/home/martin/PhpstormProjects/phpstan-src/tests/PHPStan/Analyser/data/implode.php" (Closure Object (...))
Expected type 'wrong', got type '12345' in /home/martin/PhpstormProjects/phpstan-src/tests/PHPStan/Analyser/data/implode.php on line 15.
Expected type 'wrong', got type '12345' in /home/martin/PhpstormProjects/phpstan-src/tests/PHPStan/Analyser/data/implode.php on line 16.
Failed asserting that an array is empty.
/home/martin/PhpstormProjects/phpstan-src/src/Testing/TypeInferenceTestCase.php:108
/home/martin/PhpstormProjects/phpstan-src/tests/PHPStan/Analyser/NodeScopeResolverTest.php:1138
2) PHPStan\Analyser\NodeScopeResolverTest::testAssertions with data set "/home/martin/PhpstormProjects/phpstan-src/tests/PHPStan/Analyser/data/bug-1945.php" (Closure Object (...))
Expected Maybe, actual certainty of variable $foo is Yes in /Users/herndlm/Development/source/git-forks/phpstan-src/tests/PHPStan/Analyser/data/bug-1945.php on line 23.
Expected No, actual certainty of variable $foo is Yes in /Users/herndlm/Development/source/git-forks/phpstan-src/tests/PHPStan/Analyser/data/bug-1945.php on line 47.
Failed asserting that an array is empty.
/home/martin/PhpstormProjects/phpstan-src/src/Testing/TypeInferenceTestCase.php:108
/home/martin/PhpstormProjects/phpstan-src/tests/PHPStan/Analyser/NodeScopeResolverTest.php:1138 it could be made even more compact, e.g. the file info is redundant now because one assertion failure is for one file and the file is already used as dataprovider array key. differences
|
effc76e
to
68f36dc
Compare
@@ -13,566 +13,566 @@ | |||
class NodeScopeResolverTest extends TypeInferenceTestCase | |||
{ | |||
|
|||
public function dataFileAsserts(): iterable | |||
public function dataAssertions(): iterable |
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 am wondering whether we can adjust this PR in a way that already exisiting TypeInferenceTestCase
subclasses immediately benefit from the base-class changes without modifications..?
(Do we need this new mechanism in parallel to the pre-exisiting one?)
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.
didn't figure that out yet, I think it's not possible, but maybe I'm missing some magic to make it possible :) the problems are different return and argument types for the 2 methods
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.
wondering still about the same thing.
couldn't you rename the gatherAssertTypes
method which existed before this PR to e.g. gatherAssertTypesFromFile
and implement the PRs gatherAssertions
as gatherAssertTypes
(same for assertFileAsserts
) and then we can take this changes as a drop-in replacement without needs for change in NodeScopeResolver
test..
maybe I am missing something obvious?
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 just realized that the thing which is not compatibel is https://github.com/phpstan/phpstan-src/pull/1991/files#diff-1e9b47d3e7051caa11f9d76ff7bd6ff2afb430014dd93dad916cbb8c2148f545R1139
fac1616
to
68f36dc
Compare
68f36dc
to
82846bc
Compare
This pull request has been marked as ready for review. |
should I fix conflicts here again or do something else? Otherwise I would just close it for now I guess, no worries |
Just an idea I had in mind I want to propose. This is more about the concept and not the actual implementation. I adapted
NodeScopeResolverTest
to make use of it, looks like there would be 14 more.This PR adds new methods to
TypeInferenceTestCase
that make it possible to write tests where the assert type gathering is not happening in the dataprovider, but in the actual test method. This is done by returning callbacks in the dataprovider.This has various upsides
$file
in theyield
makes PHPUnit print the test case file instead of the test case number, e.g.I don't like that these are new methods and users have to manually migrate. Not sure if this can be made "smoother". I also don't like their names. If this idea is accepted, we could also come up with completely different names and deprecate the old methods even at some point maybe.
What do people think about this?