Skip to content

Should assertType always be inside a function or can it be on the top level? #10889

Closed Answered by ondrejmirtes
calebdw asked this question in Support
Discussion options

You must be logged in to vote

I don't think it's because of performance. There might have been some performance-related issue in the past that might have manifested in this case like sebastianbergmann/phpunit#5524 or sebastianbergmann/phpunit#5758 - essentially PHPUnit taking a long time because data returned by data provider contained huge objects. But that should be solved and shouldn't influence how tests look like.

But I see two different reasons to put assertType and similar in a non-root scope:

  1. Historical: We used to use runtime reflection. Before static reflection (https://phpstan.org/blog/zero-config-analysis-with-static-reflection) there was a chance that calls below a class declaration would be executed in …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by calebdw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Support
Labels
None yet
2 participants