8000 Allow DocBlock class to be called with built-in classes by derrabus · Pull Request #4448 · sebastianbergmann/phpunit · GitHub
[go: up one dir, main page]

Skip to content

Allow DocBlock class to be called with built-in classes #4448

8000
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

Closed
wants to merge 1 commit into from
Closed

Allow DocBlock class to be called with built-in classes #4448

wants to merge 1 commit into from

Conversation

derrabus
Copy link
Contributor
@derrabus derrabus commented Sep 7, 2020

When being called on built-in classes like DateTime or ReflectionClass, the DocBlock parser fails with obscure type errors. This happens because the reflection methods getStartLine(), getEndLine() and getFileName() return false for those classes.

Since there are no doc blocks to parse on those classes, I'd expect the parser to behave the same way as for a userland class without any doc blocks. This is what I've tried to achieve with this PR.

@codecov
Copy link
codecov bot commented Sep 7, 2020

Codecov Report

Merging #4448 into master will increase coverage by 0.01%.
The diff coverage is 92.85%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #4448      +/-   ##
============================================
+ Coverage     85.14%   85.16%   +0.01%     
- Complexity     4511     4520       +9     
============================================
  Files           243      243              
  Lines         12342    12350       +8     
============================================
+ Hits          10509    10518       +9     
+ Misses         1833     1832       -1     
Impacted Files Coverage Δ Complexity Δ
src/Util/Annotation/DocBlock.php 95.69% <92.85%> (-0.41%) 68.00 <1.00> (+8.00) ⬇️
src/Runner/Version.php 84.61% <0.00%> (ø) 6.00% <0.00%> (ø%)
src/Framework/TestCase.php 89.67% <0.00%> (ø) 324.00% <0.00%> (ø%)
src/Framework/MockObject/Generator.php 95.04% <0.00%> (ø) 130.00% <0.00%> (ø%)
src/TextUI/XmlConfiguration/Generator.php 100.00% <0.00%> (ø) 1.00% <0.00%> (ø%)
src/TextUI/TestRunner.php 66.66% <0.00%> (+0.22%) 219.00% <0.00%> (ø%)
src/TextUI/Command.php 71.60% <0.00%> (+0.43%) 125.00% <0.00%> (+1.00%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8477a29...ff3d9ee. Read the comment docs.

@sebastianbergmann
Copy link
Owner

Thank you for your contribution. I appreciate the time you invested in preparing this pull request. However, I have decided not to merge it because the code in questions does not need support for built-in classes.

The DocBlock class is @internal, not covered by the backward compatibility promise for PHPUnit, and should not be used by code outside of PHPUnit itself. Its methods such as ofClass() and ofMethod() are not meant to be called for built-in classes. If they are, then that would be the bug I would like to see fixed. Please open a new ticket if you can show that this code is called for built-in classes.

@derrabus
Copy link
Contributor Author
derrabus commented Sep 8, 2020

should not be used by code outside of PHPUnit itself

I agree, but PHPUnit uses that class internally quite often without prior check for built-in classes.

In my case, the DeprecationErrorHandler from Symfony's PhpUnitBridge tries to find out if a triggered error originates from a test case of a certain group. It uses the PHPUnit\Util\Test class for this purpose, which passes the given class to DocBlock. To be fair, PHPUnit\Util\Test is also flagged as internal, but there isn't really an official API for the kind of information that we need, is there?

Anyway, I think I can catch this case and prevent the call. Thanks for the quick heads-up.

@derrabus derrabus deleted the bugfix/support-internal-classes branch September 12, 2020 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0