Example #1
0
 /**
  * This method is called when a test method did not execute successfully.
  *
  * @param Exception $e
  * @since Method available since Release 3.4.0
  */
 protected function onNotSuccessfulTest(Exception $e)
 {
     if ($e instanceof PHPUnit_Framework_ExpectationFailedException) {
         $buffer = 'Current URL: ' . $this->drivers[0]->getLocation() . "\n";
         $message = $e->getCustomMessage();
         if ($this->captureScreenshotOnFailure && !empty($this->screenshotPath) && !empty($this->screenshotUrl)) {
             $this->drivers[0]->captureEntirePageScreenshot($this->screenshotPath . DIRECTORY_SEPARATOR . $this->testId . '.png');
             $buffer .= 'Screenshot: ' . $this->screenshotUrl . '/' . $this->testId . ".png\n";
         }
     }
     try {
         $this->stop();
     } catch (RuntimeException $e) {
     }
     if ($e instanceof PHPUnit_Framework_ExpectationFailedException) {
         if (!empty($message)) {
             $buffer .= "\n" . $message;
         }
         $e->setCustomMessage($buffer);
     }
     throw $e;
 }
Example #2
0
 /**
  * Returns a description for an exception.
  *
  * @param  Exception $e
  * @return string
  * @since  Method available since Release 3.2.0
  */
 public static function exceptionToString(Exception $e)
 {
     if ($e instanceof PHPUnit_Framework_SelfDescribing) {
         if ($e instanceof PHPUnit_Framework_ExpectationFailedException) {
             $comparisonFailure = $e->getComparisonFailure();
             $description = $e->getDescription();
             $message = $e->getCustomMessage();
             if ($message == '') {
                 $buffer = '';
             } else {
                 $buffer = $message . "\n";
             }
             if ($comparisonFailure !== NULL) {
                 if ($comparisonFailure->identical()) {
                     if ($comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure_Object) {
                         $buffer .= 'Failed asserting that two variables ' . "reference the same object.\n";
                     } else {
                         $buffer .= $comparisonFailure->toString() . "\n";
                     }
                 } else {
                     if ($comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure_Scalar) {
                         $buffer .= sprintf("Failed asserting that %s matches expected %s.\n", PHPUnit_Util_Type::toString($comparisonFailure->getActual()), PHPUnit_Util_Type::toString($comparisonFailure->getExpected()));
                     } else {
                         if ($comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure_Array || $comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure_Object || $comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure_String) {
                             $buffer .= sprintf("Failed asserting that two %ss are equal.\n%s\n", strtolower(substr(get_class($comparisonFailure), 36)), $comparisonFailure->toString());
                         }
                     }
                 }
             } else {
                 $buffer .= $e->toString();
                 if (!empty($buffer)) {
                     $buffer .= "\n";
                 }
                 if (strpos($buffer, $description) === FALSE) {
                     $buffer .= $description . "\n";
                 }
             }
         } else {
             $buffer = $e->toString();
             if (!empty($buffer)) {
                 $buffer .= "\n";
             }
         }
     } else {
         if ($e instanceof PHPUnit_Framework_Error) {
             $buffer = $e->getMessage() . "\n";
         } else {
             $buffer = get_class($e) . ': ' . $e->getMessage() . "\n";
         }
     }
     return $buffer;
 }