forked from ezsystems/ezpublish-api
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
321 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
79 changes: 79 additions & 0 deletions
79
Repository/Tests/PHPUnitConstraint/ValidationErrorOccurs.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the eZ Publish Kernel package. | ||
* | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
namespace eZ\Publish\API\Repository\Tests\PHPUnitConstraint; | ||
|
||
/** | ||
* PHPUnit constraint checking that the given ValidationError message occurs in asserted ContentFieldValidationException. | ||
* | ||
* @see \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException | ||
* @see \eZ\Publish\SPI\FieldType\ValidationError | ||
*/ | ||
class ValidationErrorOccurs extends \PHPUnit_Framework_Constraint | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $expectedValidationErrorMessage; | ||
|
||
/** | ||
* @param string $expectedValidationErrorMessage | ||
*/ | ||
public function __construct($expectedValidationErrorMessage) | ||
{ | ||
parent::__construct(); | ||
|
||
$this->expectedValidationErrorMessage = $expectedValidationErrorMessage; | ||
} | ||
|
||
/** | ||
* @param \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException $other | ||
* | ||
* @return bool | ||
*/ | ||
protected function matches($other) | ||
{ | ||
foreach ($other->getFieldErrors() as $fieldId => $errors) { | ||
foreach ($errors as $languageCode => $fieldErrors) { | ||
foreach ($fieldErrors as $fieldError) { | ||
/** @var \eZ\Publish\Core\FieldType\ValidationError $fieldError */ | ||
if ($fieldError->getTranslatableMessage()->message === $this->expectedValidationErrorMessage) { | ||
return true; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* @param \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException $other | ||
* | ||
* @return string | ||
*/ | ||
protected function failureDescription($other) | ||
{ | ||
return sprintf( | ||
'%s::getFieldErrors = %s %s', | ||
get_class($other), | ||
var_export($other->getFieldErrors(), true), | ||
$this->toString() | ||
); | ||
} | ||
|
||
/** | ||
* Returns a string representation of the object. | ||
* | ||
* @return string | ||
*/ | ||
public function toString() | ||
{ | ||
return "contains a ValidationError with the message '{$this->expectedValidationErrorMessage}'"; | ||
} | ||
} |