Update expectations for AbstractConstraintValidatorTestCase - #37
Merged
frankdekker merged 8 commits intoFeb 11, 2026
Conversation
Contributor
There was a problem hiding this comment.
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 inassertHandlesIncorrectConstraintType(),expectNoViolations(),expectViolation(), andexpectBuildViolation()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 likeonce(),never(), andatLeastOnce()are consistently called usingself::prefix. All occurrences in this method should useself::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.
…validator-test-case' into fix-expects-abstract-constraint-validator-test-case
frankdekker
approved these changes
Feb 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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