Skip to content
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

Commenting/TestsHaveCoversTag: support PHP 8.1 + 8.2, bug fix and various other improvements #331

Merged
merged 9 commits into from
Nov 4, 2023

Conversation

jrfnl
Copy link
Collaborator

@jrfnl jrfnl commented Nov 4, 2023

Commenting/TestsHaveCoversTag: minor test improvements

Add some more variation of class/method prefixes to the tests to better safeguard the handling of those.

Commenting/TestsHaveCoversTag: rename test case file

... to allow for additional test case files to be added.

Commenting/TestsHaveCoversTag: add some extra tests

... for situations previously not (yet) covered by tests.

Commenting/TestsHaveCoversTag: make non-interface methods private

As the sniff class is now final (since PR #319), there is no need for any protected methods, so let's make these private.

Commenting/TestsHaveCoversTag: bug fix - prevent PHP 8.1 deprecation notice during live coding [1]

When scanning code during live coding in an IDE, the ObjectDeclarations::getName() method could return null.

This fix prevents a PHP 8.1 "substr(): Passing null to parameter #1 ($string) of type string is deprecated" deprecation notice in that situation.

Includes test.

Commenting/TestsHaveCoversTag: bug fix - prevent PHP 8.1 deprecation notice during live coding [2]

When scanning code during live coding/while scanning code containing a parse error, the FunctionDeclarations::getName() method could return null.

This fix prevents a PHP 8.1 "stripos(): Passing null to parameter #1 ($string) of type string is deprecated" deprecation notice in that situation.

Includes test.

Commenting/TestsHaveCoversTag: bug fix - prevent false positive on global function

Test functions in the context of PHPUnit tests must be OO methods in a child class of the PHPUnit native TestCase class.

Global functions will never be run as tests, so can be disregarded for the purposes of this sniff without further examination.

Includes test.

Commenting/TestsHaveCoversTag: minor tweaks

  • Remove an unnecessary condition.
  • Remove a return which will never receive a value to return.
  • Bow out earlier if something useful was found. No need to continue examining.
  • Minor doc updates for future reference.

Commenting/TestsHaveCoversTag: handle PHP 8.2 readonly classes

While probably rare, the sniff should still find the docblock for a test class marked as readonly without breaking on the readonly keyword.

Fixed now. Includes tests.

Add some more variation of class/method prefixes to the tests to better safeguard the handling of those.
... to allow for additional test case files to be added.
... for situations previously not (yet) covered by tests.
As the sniff class is now `final` (since PR 319), there is no need for any `protected` methods, so let's make these `private`.
…notice during live coding [1]

When scanning code during live coding in an IDE, the `ObjectDeclarations::getName()` method could return `null`.

This fix prevents a PHP 8.1 "substr(): Passing null to parameter #1 ($string) of type string is deprecated" deprecation notice in that situation.

Includes test.
…notice during live coding [2]

When scanning code during live coding/while scanning code containing a parse error, the `FunctionDeclarations::getName()` method could return `null`.

This fix prevents a PHP 8.1 "stripos(): Passing null to parameter #1 ($string) of type string is deprecated" deprecation notice in that situation.

Includes test.
…obal function

Test functions in the context of PHPUnit tests **must** be OO methods in a child class of the PHPUnit native `TestCase` class.

Global functions will never be run as tests, so can be disregarded for the purposes of this sniff without further examination.

Includes test.
* Remove an unnecessary condition.
* Remove a `return` which will never receive a value to return.
* Bow out earlier if something useful was found. No need to continue examining.
* Minor doc updates for future reference.
While probably rare, the sniff should still find the docblock for a test class marked as `readonly` without breaking on the `readonly` keyword.

Fixed now. Includes tests.
@coveralls
Copy link

Coverage Status

coverage: 97.508% (+0.4%) from 97.146%
when pulling d36d2ae on JRF/yoastcs-testshavecoverstag-various-improvements
into 06cf5d2 on develop.

@jrfnl jrfnl merged commit 0a366ae into develop Nov 4, 2023
26 checks passed
@jrfnl jrfnl deleted the JRF/yoastcs-testshavecoverstag-various-improvements branch November 4, 2023 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants