The exception contains the error message and optionally a PHPUnit_Framework_ComparisonFailure which is used to generate diff output of the failed expectations.
Author: Sebastian Bergmann (sebastian@phpunit.de)
Author: Bernhard Schussek (bschussek@2bepublished.at)
Inheritance: extends PHPUnit_Framework_AssertionFailedError
Exemple #1
0
 /**
  * @param Response $response
  * @param integer  $statusCode
  * @param string   $entityName
  * @param string   $requestType
  */
 protected function assertApiResponseStatusCodeEquals(Response $response, $statusCode, $entityName, $requestType)
 {
     try {
         $this->assertResponseStatusCodeEquals($response, $statusCode);
     } catch (\PHPUnit_Framework_ExpectationFailedException $e) {
         $e = new \PHPUnit_Framework_ExpectationFailedException(sprintf('Wrong %s response for "%s" request for entity: "%s". Error message: %s', $statusCode, $requestType, $entityName, $e->getMessage()), $e->getComparisonFailure());
         throw $e;
     }
 }
 public function __construct($message, $expectedImage, $currentImage, $deviationImage)
 {
     $this->deviationImage = $deviationImage;
     $this->currentImage = $currentImage;
     $this->expectedImage = $expectedImage;
     parent::__construct($message);
 }
 public function __construct($message, ComparisonResult $comparisonResult, Storage $storage, $identifier = "leer")
 {
     $this->result = $comparisonResult;
     $this->storage = $storage;
     $this->identifier = $identifier;
     parent::__construct($message);
 }
 public function toString()
 {
     $result = parent::toString();
     if (!empty($this->diff)) {
         $result .= "\n" . $this->diff;
     }
     return $result;
 }
Exemple #5
0
 /**
  * Make the exception message more informative.
  * @param $e Exception
  * @param $testObject string
  * @return Exception
  */
 protected function improveException($e, $testObject)
 {
     $improvedMessage = "Error while testing {$testObject}: " . $e->getMessage();
     if (is_a($e, 'PHPUnit_Framework_ExpectationFailedException')) {
         $e = new PHPUnit_Framework_ExpectationFailedException($improvedMessage, $e->getComparisonFailure());
     } elseif (is_a($e, 'PHPUnit_Framework_Exception')) {
         $e = new PHPUnit_Framework_Exception($improvedMessage, $e->getCode());
     }
     return $e;
 }
 public function __construct($command = '', $locator = '')
 {
     $this->command = $command;
     $locator_description = strlen($locator) > 0 ? '<' . $locator . '>' : 'this element';
     parent::__construct("Could not interact with {$locator_description} because it is not visible\nCommand: {$command}");
 }
Exemple #7
0
 /**
  * Assert response status code equals
  *
  * @param Response $response
  * @param int      $statusCode
  */
 public static function assertResponseStatusCodeEquals(Response $response, $statusCode)
 {
     try {
         \PHPUnit_Framework_TestCase::assertEquals($statusCode, $response->getStatusCode());
     } catch (\PHPUnit_Framework_ExpectationFailedException $e) {
         if ($statusCode < 400 && $response->getStatusCode() >= 400 && $response->headers->contains('Content-Type', 'application/json')) {
             $content = self::jsonToArray($response->getContent());
             if (!empty($content['message'])) {
                 $errors = null;
                 if (!empty($content['errors'])) {
                     $errors = is_array($content['errors']) ? json_encode($content['errors']) : $content['errors'];
                 }
                 $e = new \PHPUnit_Framework_ExpectationFailedException($e->getMessage() . ' Error message: ' . $content['message'] . ($errors ? '. Errors: ' . $errors : ''), $e->getComparisonFailure());
             }
         }
         throw $e;
     }
 }
 public function __construct($msg)
 {
     parent::__construct($msg, null, null);
 }
Exemple #9
0
 /**
  * @param \PHPUnit_Framework_ExpectationFailedException $e
  * @param $state
  *
  * @throws \Exception
  */
 private function throwException(\PHPUnit_Framework_ExpectationFailedException $e, $state)
 {
     throw new \PHPUnit_Framework_ExpectationFailedException(sprintf("Invalid state on %s:\r\n\r\n%s", $state, $e->getMessage()), $e->getComparisonFailure(), $e->getPrevious());
 }