Skip to content

Conversation

@aik099
Copy link
Member

@aik099 aik099 commented Jun 25, 2025

Solves the same problem as #72 , but in different way using my own recommendations in that PR:

  • create a bridge between Hamcrest and PHPUnit assertion tracking code (now Hamcrest performed assertions are seen by the PHPUnit);
  • mark 3 tests, that actually don't perform any assertions using the @doesNotPerformAssertions annotation.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses PHPUnit’s risky test warnings by integrating Hamcrest assertion counts into PHPUnit and marking tests without assertions to suppress warnings.

  • Introduces a reset/Add assertion-count bridge between Hamcrest and PHPUnit in AbstractMatcherTest
  • Adds @doesNotPerformAssertions to tests that don’t invoke any assertions
  • Updates child matcher tests to call the new parent setup logic via parent::setUpTest()

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/Hamcrest/UtilTest.php Annotated a no-assertion test with @doesNotPerformAssertions
tests/Hamcrest/Text/StringStartsWithTest.php Calls parent::setUpTest() in setUpTest()
tests/Hamcrest/Text/StringEndsWithTest.php Calls parent::setUpTest() in setUpTest()
tests/Hamcrest/Text/StringContainsTest.php Calls parent::setUpTest() in setUpTest()
tests/Hamcrest/Text/StringContainsInOrderTest.php Calls parent::setUpTest() in setUpTest()
tests/Hamcrest/Text/StringContainsIgnoringCaseTest.php Calls parent::setUpTest() in setUpTest()
tests/Hamcrest/Text/IsEqualIgnoringWhiteSpaceTest.php Calls parent::setUpTest() in setUpTest()
tests/Hamcrest/FeatureMatcherTest.php Calls parent::setUpTest() in setUpTest()
tests/Hamcrest/Core/SetTest.php Calls parent::setUpTest() in setUpTest()
tests/Hamcrest/Core/IsInstanceOfTest.php Calls parent::setUpTest() in setUpTest()
tests/Hamcrest/Core/CombinableMatcherTest.php Calls parent::setUpTest() in setUpTest()
tests/Hamcrest/AbstractMatcherTest.php Adds @before/@after hooks to reset and add Hamcrest assertion counts and marks two tests with @doesNotPerformAssertions
Comments suppressed due to low confidence (1)

tests/Hamcrest/AbstractMatcherTest.php:86

  • [nitpick] Consider renaming tearDownTest to PHPUnit’s standard tearDown() (and similarly setUpTest to setUp()) to follow conventions and improve clarity instead of relying solely on annotation hooks.
    protected function tearDownTest()

Copy link
Contributor

@pscheit pscheit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, this looks good!

@pscheit
Copy link
Contributor

pscheit commented Jun 25, 2025

[nitpick] Consider renaming tearDownTest to PHPUnit’s standard tearDown() (and similarly setUpTest to setUp()) to follow conventions and improve clarity instead of relying solely on annotation hooks.

This is a valid Co-Pilot comment though ;)

before:

/**
 * @after
 */
protected function tearDownTest();

after:

protected function tearDown(): void

imho this is a well-known convention when using phpunit.

@aik099
Copy link
Member Author

aik099 commented Jun 25, 2025

This is a valid Co-Pilot comment though ;)

In restrospective it isn't considering, that method signatures in PHPUnit built-in methods change overtime and to support newer PHPUnit versions we constantly need to adjust ours as well :(

@pscheit
Copy link
Contributor

pscheit commented Jun 25, 2025

After the native :void was added they were pretty stable

@aik099
Copy link
Member Author

aik099 commented Jun 26, 2025

Let's keep it simple in this PR. We can always return to this topic to perform library-wide rename.

@aik099 aik099 merged commit 8cf45b1 into hamcrest:master Jun 26, 2025
6 checks passed
@aik099 aik099 deleted the risky-test-fix branch June 26, 2025 10:01
@pscheit
Copy link
Contributor

pscheit commented Jun 26, 2025

yeah, I wasnt referring to that. Totally on your side keeping the PRs small and tidy.

Just sometimes it's just impossible to do so :)

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