Skip to content

Commit

Permalink
Use ConstraintParameterException::getViolationMessage()
Browse files Browse the repository at this point in the history
In preparation for ViolationMessage in ConstraintParameterException,
start using getViolationMessage() instead of getMessage(). Right now
they’re equivalent, but all the places touched here can also accept a
proper ViolationMessage.

Bug: T187186
Change-Id: I6af676955af65c6d0c5300fc04cc6012eb91d403
  • Loading branch information
lucaswerkmeister committed Feb 16, 2018
1 parent 1657bd8 commit 3e5a320
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/ConstraintCheck/DelegatingConstraintChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ private function checkConstraintsForMainSnak(
try {
$exceptions = $this->constraintParameterParser->parseExceptionParameter( $parameters );
} catch ( ConstraintParameterException $e ) {
$result[] = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getMessage() );
$result[] = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() );
continue;
}

Expand Down Expand Up @@ -542,7 +542,7 @@ private function getCheckResultFor( Context $context, Constraint $constraint ) {
try {
$result = $checker->checkConstraint( $context, $constraint );
} catch ( ConstraintParameterException $e ) {
$result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getMessage() );
$result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() );
} catch ( SparqlHelperException $e ) {
$message = new ViolationMessage( 'wbqc-violation-message-sparql-error' );
$result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message );
Expand All @@ -555,7 +555,7 @@ private function getCheckResultFor( Context $context, Constraint $constraint ) {
$constraintStatus = $this->constraintParameterParser
->parseConstraintStatusParameter( $constraint->getConstraintParameters() );
} catch ( ConstraintParameterException $e ) {
$result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getMessage() );
$result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() );
$constraintStatus = null;
}
if ( $constraintStatus === null ) {
Expand Down Expand Up @@ -601,7 +601,7 @@ private function handleScope(
$constraint->getConstraintTypeItemId()
);
} catch ( ConstraintParameterException $e ) {
return new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getMessage() );
return new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() );
}
if ( $checkedContextTypes === null ) {
$checkedContextTypes = $checker->getDefaultContextTypes();
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/Helper/ConstraintParameterParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private function assertThrowsConstraintParameterException( $method, array $argum
$this->constraint,
[],
CheckResult::STATUS_VIOLATION,
$exception->getMessage()
$exception->getViolationMessage()
);
$this->assertViolation( $checkResult, $messageKey );
}
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/Helper/SparqlHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ public function testMatchesRegularExpressionWithSparqlBadRegex() {
$this->getMockBuilder( Constraint::class )->disableOriginalConstructor()->getMock(),
[],
CheckResult::STATUS_VIOLATION,
$exception->getMessage()
$exception->getViolationMessage()
);
$this->assertViolation( $checkResult, $messageKey );
}
Expand Down

0 comments on commit 3e5a320

Please sign in to comment.