Skip to content

Update expectations for AbstractConstraintValidatorTestCase - #37

Merged
frankdekker merged 8 commits into
123inkt:masterfrom
cardoso123inkt:fix-expects-abstract-constraint-validator-test-case
Feb 11, 2026
Merged

Update expectations for AbstractConstraintValidatorTestCase#37
frankdekker merged 8 commits into
123inkt:masterfrom
cardoso123inkt:fix-expects-abstract-constraint-validator-test-case

Conversation

@cardoso123inkt

Copy link
Copy Markdown
Contributor

In this PR, the abstract constraint validator test base is updated to define explicit expectations for all internally created mocks.

Previously, the base test instantiated mocks for ExecutionContextInterface, ConstraintViolationBuilder, and Constraint without guaranteeing that each test configured expectations for them. With stricter PHPUnit behavior, this resulted in failures such as:

No expectations were configured for mock object ConstraintViolationBuilder
No expectations were configured for mock object ExecutionContextInterface

Instead of using #[AllowMockObjectsWithoutExpectations] to suppress these warnings, the test case is adjusted so that all relevant interactions are covered through explicit expects() calls.

Helper methods like expectNoViolations(), expectViolation(), and expectBuildViolation() now ensure that expectations are always defined on the execution context and violation builder

Copilot AI review requested due to automatic review settings February 11, 2026 07:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 attempts to update the abstract constraint validator test base class to define explicit expectations for all internally created mocks, addressing stricter PHPUnit behavior that now requires expectations to be configured for mock objects. The changes add never() expectations on both the execution context and violation builder in helper methods to ensure mocks always have expectations defined.

Changes:

  • Added never() expectations on mock objects in assertHandlesIncorrectConstraintType(), expectNoViolations(), expectViolation(), and expectBuildViolation() methods
  • Changed from static:: to $this-> for PHPUnit matcher method calls (once(), never())
Comments suppressed due to low confidence (1)

src/Symfony/AbstractConstraintValidatorTestCase.php:130

  • The change from static::once() to $this->once() is inconsistent with the established codebase convention. Throughout the codebase (e.g., AbstractControllerTestCase.php lines 50, 53, 61, 85, 104, 118), PHPUnit matcher methods like once(), never(), and atLeastOnce() are consistently called using self:: prefix. All occurrences in this method should use self::once() instead of $this->once() to maintain consistency.
        $this->executionContext->expects(static::once())->method('buildViolation')->with($message, $parameters)->willReturn($this->violationBuilder);
        if ($atPath !== null) {
            $this->violationBuilder->expects(static::once())->method('atPath')->with($atPath)->willReturnSelf();
        }
        if ($invalidValue !== self::IGNORE_INVALID_VALUE) {
            $this->violationBuilder->expects(static::once())->method('setInvalidValue')->with($invalidValue)->willReturnSelf();
        }
        $this->violationBuilder->expects(static::once())->method('addViolation');

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Symfony/AbstractConstraintValidatorTestCase.php Outdated
Comment thread src/Symfony/AbstractConstraintValidatorTestCase.php Outdated
Comment thread src/Symfony/AbstractConstraintValidatorTestCase.php Outdated
Comment thread src/Symfony/AbstractConstraintValidatorTestCase.php Outdated
Comment thread src/Symfony/AbstractConstraintValidatorTestCase.php Outdated
Comment thread src/Symfony/AbstractConstraintValidatorTestCase.php Outdated
Comment thread src/Symfony/AbstractConstraintValidatorTestCase.php Outdated
Comment thread src/Symfony/AbstractConstraintValidatorTestCase.php Outdated
Comment thread src/Symfony/AbstractConstraintValidatorTestCase.php Outdated
@frankdekker
frankdekker merged commit 9aa9dbc into 123inkt:master Feb 11, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants