getComparisonFailure() public method

public getComparisonFailure ( ) : PHPUnit_Framework_ComparisonFailure
return PHPUnit_Framework_ComparisonFailure
Ejemplo n.º 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;
     }
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
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;
     }
 }
Ejemplo n.º 4
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());
 }