Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IsEqualHtml should extend PhpUnit Constraint #194

Merged
Merged
Prev Previous commit
Next Next commit
Update ExpectationsMet
  • Loading branch information
unfulvio-godaddy committed Jan 3, 2023
commit 4621eb0b48bcdc45c4382da315c03c14ec74bc53
38 changes: 32 additions & 6 deletions php/WP_Mock/Tools/Constraints/ExpectationsMet.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,32 @@
use Mockery;
use Exception;

class ExpectationsMet extends \PHPUnit\Framework\Constraint\Constraint
/**
* Expectations-met constraint.
*/
class ExpectationsMet extends Constraint
{
private $_mockery_message;
/** @var string */
private $failureDescription;

/**
* Evaluates the constraint for parameter $other.
*
* Returns true if the constraint is met, false otherwise.
*
* @param mixed $other
* @return bool
*/
public function matches($other): bool
{
try {
Mockery::getContainer()->mockery_verify();
} catch (Exception $e) {
$this->_mockery_message = $e->getMessage();
} catch (Exception $exception) {
$this->failureDescription = $exception->getMessage();

return false;
}

return true;
}

Expand All @@ -28,14 +42,26 @@ public function matches($other): bool
*/
public function toString(): string
{
return 'WP Mock expectations are met';
return 'WP_Mock expectations are met';
}

/**
* Gets the additional failure description.
*
* @param mixed $other
* @return string
*/
protected function additionalFailureDescription($other): string
{
return str_replace(array( "\r", "\n" ), '', (string) $this->_mockery_message);
return str_replace(["\r", "\n"], '', $this->failureDescription);
}

/**
* Gets the failure description.
*
* @param mixed $other
* @return string
*/
protected function failureDescription($other): string
{
return $this->toString();
Expand Down