public function endTest(PHPUnit_Framework_Test $test, $time)
 {
     $startTime = $this->timer[$test->getName()];
     $duration = number_format($this->getCurrentTime() - $startTime, 4);
     $message = $test->getName() . ' executed in ' . $duration . 's';
     $this->log->addInfo($message);
 }
 public function endTest(PHPUnit_Framework_Test $test, $time)
 {
     //printf("Test '%s' ended.\n", $test->getName());
     if ($this->_fails == 0 && $this->_errors == 0) {
         echo ' Test passed';
     } else {
         echo "There were {$this->_fails} failures for " . $test->getName() . "</br>\n";
         echo "There were {$this->_errors} errors for " . $test->getName() . "</div>\n";
     }
     echo '</div>';
 }
Exemple #3
0
 public function addError(\PHPUnit_Framework_Test $test, \Exception $e, $time)
 {
     $this->logger->info("Test " . $test->getName() . " threw error");
     $errorTestcases = Registry::getInstance()->get(self::ERR_TESTCASES_KEY);
     $errorArray = array();
     $errorArray[0] = $test;
     $errorArray[1] = $e;
     array_push($errorTestcases, $errorArray);
     Registry::getInstance()->replace(self::ERR_TESTCASES_KEY, $errorTestcases);
     $this->logger->info("Adding errored test " . $test->getName() . " to the Registry " . print_r($errorTestcases, true));
     $this->logger->info("End " . __METHOD__);
 }
 /**
  * @param \PHPUnit_Framework_Test $test
  * @return string
  */
 protected function getTestName(\PHPUnit_Framework_Test $test)
 {
     if ($test instanceof \PHPUnit_Framework_TestCase) {
         $name = $test->getName();
     } elseif ($test instanceof \PHPUnit_Framework_TestSuite) {
         $name = $test->getName();
     } elseif ($test instanceof \PHPUnit_Framework_SelfDescribing) {
         $name = $test->toString();
     } else {
         $name = get_class($test);
     }
     return $name;
 }
Exemple #5
0
    /**
     * Adds an error to the list of errors.
     *
     * @param  PHPUnit_Framework_Test $test
     * @param  Exception              $e
     * @param  float                  $time
     */
    public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
    {
        $message = "\n" . $e->getMessage();

        if ($e instanceof PHPUnit_Framework_ExpectationFailedException) {
            /** @var $e PHPUnit_Framework_ExpectationFailedException */
        	//$message .= "\n" . $e->getComparisonFailure()->toString();
        }

        $name = $test->getName(false);
        
        $mail = new Enlight_Components_Mail();
        
        $mail->addTo($this->mailRecipients);
        $mail->setSubject('PHPUnit test "' . $name . '" failed.');
        $mail->setBodyText($message);

        if($test instanceof Enlight_Components_Test_Selenium_TestCase
          && $e instanceof PHPUnit_Framework_ExpectationFailedException
          && $screenshot = $test->getFullScreenshot()) {
            $filename = basename($test->getFullScreenshotUrl());
            /** @var $test Enlight_Components_Test_Selenium_TestCase */
            $mail->createAttachment(
                $screenshot,
                Zend_Mime::TYPE_OCTETSTREAM,
                Zend_Mime::DISPOSITION_ATTACHMENT,
                Zend_Mime::ENCODING_BASE64,
                $filename
            );
        }
        
        $mail->send($this->mailTransport);
    }
 public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
 {
     printf("Test '%s' failed.\n", $test->getName());
     echo "RESPONSE\n\n";
     echo "Status Code: " . $test->getResponse()->getHttpResponseCode() . "\n\n";
     echo "Headers:\n\n";
     foreach ($test->getResponse()->getHeaders() as $header) {
         $replace = 'false';
         if ($header['replace'] === true) {
             $replace = 'true';
         }
         echo "\t {$header['name']} - {$header['value']} (replace: {$replace})\n";
     }
     echo "\n";
     echo "Body:\n\n" . $test->getResponse()->getBody() . "\n\n";
     if ($test->getResponse()->isException()) {
         echo "Exceptions:\n\n";
         foreach ($test->getResponse()->getException() as $exception) {
             echo "\t * Message: {$exception->getMessage()}\n";
             echo "\t * File:    {$exception->getFile()}\n";
             echo "\t * Line:    {$exception->getLine()}\n";
             echo "\n";
         }
     }
 }
 public function endTest(PHPUnit_Framework_Test $test, $time)
 {
     $current = time();
     $took = $current - $this->time;
     if ($took > $this->timeLimit) {
         echo "\nName: " . $test->getName() . " took " . $took . " second(s) (from: {$this->time}, to: {$current})\n";
     }
 }
 public function endTest(\PHPUnit_Framework_Test $test, $time)
 {
     $time = sprintf('%0.3f sec', microtime(1) - $this->timeTest);
     $count = $test->getCount();
     $tabs = ceil((29 - strlen($test->getName())) / 8);
     echo str_repeat("\t", $tabs) . "{$count} Assertions";
     echo $this->colorize("\t{$time}", 'green');
 }
 public function endTest(PHPUnit_Framework_Test $test, $time)
 {
     $t =& $this->results[$this->currentSuite][$test->getName()];
     if (!isset($t['status'])) {
         $t['status'] = 'passed';
     }
     $t['time'] = $time;
     $this->currentTest = null;
 }
 /**
  * @param \PHPUnit_Framework_Test $test
  * @param $time
  */
 public function endTest(\PHPUnit_Framework_Test $test, $time)
 {
     $this->executionTime = new TimeMeasurement($time);
     $this->memoryUsage = memory_get_usage() - $this->memoryUsage;
     $this->memoryPeakIncrease = memory_get_peak_usage() - $this->memoryPeakIncrease;
     if ($this->haveToSaveTestMeasurement($time)) {
         $this->testMeasurementCollection[] = new TestMeasurement($test->getName(), get_class($test), $this->executionTime, new MemoryMeasurement($this->memoryUsage), new MemoryMeasurement($this->memoryPeakIncrease));
     }
 }
 public function endTest(PHPUnit_Framework_Test $test, $time)
 {
     //$fmt =  "\nTime: %s ms Name: %s  (from: %s, to: %s)";
     $fmt = "\nTime: %s ms Name: %s ";
     $current = microtime();
     $took = $current - $this->time;
     if ($took > $this->timeLimit) {
         error_log(sprintf($fmt, $took, $test->getName(), $this->time, $current));
     }
 }
Exemple #12
0
 /**
  * Persists the given message.
  *
  * @param string $message
  * @param string $level
  */
 public function log($message, $level = '')
 {
     $this->serializer->register('Array', $message->getHeader());
     $this->serializer->register('Xml', $message->getBody());
     $this->serializer->setDocumentRoot('response');
     // due to time issues just a bad hack .. to be refactored asap
     $path = TEST_DIR . '/_files/responses';
     $file = $path . '/' . $this->generateFilename($this->test->getName());
     $filename = $file . '.xml';
     if (file_exists($filename)) {
         rename($filename, $file . microtime(true) . '.xml');
     }
     file_put_contents($filename, $this->serializer->serialize());
 }
Exemple #13
0
 public function getDocComment(PHPUnit_Framework_Test $test)
 {
     $class = new ReflectionClass($test);
     $method = $class->getMethod($test->getName(false));
     $docComment = $method->getDocComment();
     $docComment = preg_replace('#[ \\t]*(?:\\/\\*\\*|\\*\\/|\\*)?[ ]{0,1}(.*)?#', '$1', $docComment);
     $docComment = "\n" . $docComment;
     $endOfDescription = strpos($docComment, "\n@");
     if ($endOfDescription !== false) {
         $docComment = substr($docComment, 0, $endOfDescription);
     }
     $docComment = trim($docComment);
     return $docComment;
 }
Exemple #14
0
 public function getDocComment(PHPUnit_Framework_Test $test)
 {
     $comment = array();
     try {
         $class = new ReflectionClass($test);
         $method = $class->getMethod($test->getName(false));
         $docComment = $method->getDocComment();
         $docComment = explode(PHP_EOL, $docComment);
         foreach ($docComment as $line) {
             $line = trim($line);
             $line = trim($line, '*');
             $line = trim($line);
             if (substr($line, 0, 1) != '@' && strlen($line) > 1) {
                 $comment[] = $line;
             }
         }
     } catch (Exception $e) {
     }
     return join(PHP_EOL, $comment);
 }
Exemple #15
0
 public function startTest(\PHPUnit_Framework_Test $test)
 {
     if ($test instanceof \PHPUnit_Framework_Warning) {
         return;
     }
     if (!$test instanceof AbstractTestCase) {
         throw new \InvalidArgumentException('Test case must be descendant of Lmc\\Steward\\Test\\AbstractTestCase');
     }
     $config = ConfigProvider::getInstance();
     // Initialize NullWebDriver if self::NO_BROWSER_ANNOTATION is used on testcase class or test method
     $testCaseAnnotations = AnnotationsParser::getAll(new \ReflectionClass($test));
     $testAnnotations = AnnotationsParser::getAll(new \ReflectionMethod($test, $test->getName(false)));
     if (isset($testCaseAnnotations[self::NO_BROWSER_ANNOTATION]) || isset($testAnnotations[self::NO_BROWSER_ANNOTATION])) {
         $test->wd = new NullWebDriver();
         $test->log('Initializing Null WebDriver for "%s::%s" (@%s annotation used %s)', get_class($test), $test->getName(), self::NO_BROWSER_ANNOTATION, isset($testCaseAnnotations[self::NO_BROWSER_ANNOTATION]) ? 'on class' : 'on method');
         return;
     }
     // Initialize real WebDriver otherwise
     $test->log('Initializing "%s" WebDriver for "%s::%s"', $config->browserName, get_class($test), $test->getName());
     $capabilities = new \DesiredCapabilities([\WebDriverCapabilityType::BROWSER_NAME => $config->browserName, \WebDriverCapabilityType::PLATFORM => \WebDriverPlatform::ANY]);
     $this->createWebDriver($test, $config->serverUrl . '/wd/hub', $this->setupCustomCapabilities($capabilities, $config->browserName), $connectTimeoutMs = 2 * 60 * 1000, $requestTimeoutMs = 60 * 60 * 1000);
 }
Exemple #16
0
 /**
  * A failure occurred.
  *
  * @param  PHPUnit_Framework_Test                 $test
  * @param  PHPUnit_Framework_AssertionFailedError $e
  * @param  float                                  $time
  */
 public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
 {
     $this->_messages[] = "Test FAILED: " . $test->getName() . ": " . $e->getMessage();
 }
 /**
  * Skipped test.
  *
  * @param PHPUnit_Framework_Test $test
  * @param \Exception $e
  * @param float $time
  * @return void
  * @author Karsten Dambekalns <*****@*****.**>
  */
 public function addSkippedTest(\PHPUnit_Framework_Test $test, \Exception $e, $time)
 {
     echo '<div class="test skipped"><strong>Skipped test</strong> <em>' . $test->getName() . '</em> ' . '<img src="_Resources/Static/Packages/Testing/Media/skipped.png" alt="Detail" onclick="if(document.getElementById(\'test' . $this->currentTestNumber . '\').style.display==\'none\') document.getElementById(\'test' . $this->currentTestNumber . '\').style.display=\'block\'; else document.getElementById(\'test' . $this->currentTestNumber . '\').style.display=\'none\'" />' . '<div class="testdetail" id="test' . $this->currentTestNumber . '">' . $e->getFile() . ':' . $e->getLine() . '<br />' . htmlspecialchars($e->getMessage()) . '<br /><div class="testoutput">' . $this->getTestOutput() . '</div></div></div>';
     $this->resultArray['skipped']++;
     $this->flushOutputBuffer();
 }
 /**
  * @param string                 $message
  * @param PHPUnit_Framework_Test $test
  * @param Exception              $e
  *
  * @return string
  */
 protected function composeMessage($message, PHPUnit_Framework_Test $test, Exception $e)
 {
     $message = "Test {$message} (" . $test->getName() . " in class " . get_class($test) . "): " . $e->getMessage();
     if ($e instanceof PHPUnit_Framework_ExpectationFailedException && $e->getComparisonFailure()) {
         $message .= "\n" . $e->getComparisonFailure()->getDiff();
     }
     return $message;
 }
Exemple #19
0
 public function startTest(PHPUnit_Framework_Test $test)
 {
     echo "\n" . $test->getName() . '... ';
 }
Exemple #20
0
 /**
  * Inserts a node into the tree.
  *
  * @param  PHPUnit_Framework_Test $test
  * @throws PDOException
  */
 protected function insertNode(PHPUnit_Framework_Test $test)
 {
     $isLeaf = (int) (!$test instanceof PHPUnit_Framework_TestSuite);
     $this->dbh->beginTransaction();
     $stmt = $this->dbh->prepare('SELECT node_right
          FROM test
         WHERE test_id = :testId;');
     $stmt->bindParam(':testId', $this->testSuites[count($this->testSuites) - 1]['id'], PDO::PARAM_INT);
     $stmt->execute();
     $right = (int) $stmt->fetchColumn();
     unset($stmt);
     $stmt = $this->dbh->prepare('UPDATE test
           SET node_left = node_left + 2
         WHERE node_root = :root
           AND node_left > :left;');
     $stmt->bindParam(':root', $this->testSuites[0]['id'], PDO::PARAM_INT);
     $stmt->bindParam(':left', $right, PDO::PARAM_INT);
     $stmt->execute();
     $stmt = $this->dbh->prepare('UPDATE test
           SET node_right  = node_right + 2
         WHERE node_root   = :root
           AND node_right >= :right;');
     $stmt->bindParam(':root', $this->testSuites[0]['id'], PDO::PARAM_INT);
     $stmt->bindParam(':right', $right, PDO::PARAM_INT);
     $stmt->execute();
     $testName = $test->getName();
     $left = $right;
     $right = $right + 1;
     $stmt = $this->dbh->prepare('INSERT INTO test
                    (run_id, test_name, test_result, test_message,
                     test_execution_time, node_root, node_left, node_right,
                     node_is_leaf)
              VALUES(:runId, :testName, 0, "", 0, :root, :left, :right,
                     :isLeaf);');
     $stmt->bindParam(':runId', $this->runId, PDO::PARAM_INT);
     $stmt->bindParam(':testName', $testName, PDO::PARAM_STR);
     $stmt->bindParam(':root', $this->testSuites[0]['id'], PDO::PARAM_INT);
     $stmt->bindParam(':left', $left, PDO::PARAM_INT);
     $stmt->bindParam(':right', $right, PDO::PARAM_INT);
     $stmt->bindParam(':isLeaf', $isLeaf, PDO::PARAM_INT);
     $stmt->execute();
     $this->currentTestId = $this->dbh->lastInsertId();
     $this->dbh->commit();
     if (!$test instanceof PHPUnit_Framework_TestSuite) {
         $test->__db_id = $this->currentTestId;
     }
     return $this->currentTestId;
 }
 public function endTest(PHPUnit_Framework_Test $test, $time)
 {
     if ($time > 10) {
         printf("Test '%s' ran for %s seconds.\n", $test->getName(), $time);
     }
 }
Exemple #22
0
 public function startTest(PHPUnit_Framework_Test $test)
 {
     $this->current['name'] = $test->getName(FALSE);
     $this->current['description'] = $test->toString();
     $this->current['result'] = 'passed';
 }
 /**
  * Paints the test pass with a breadcrumbs
  * trail of the nesting test suites below the
  * top level test.
  *
  * @param PHPUnit_Framework_Test $test Test method that just passed
  * @param float $time time spent to run the test method
  * @return void
  */
 public function paintPass(PHPUnit_Framework_Test $test, $time = null)
 {
     if (isset($this->params['showPasses']) && $this->params['showPasses']) {
         echo "<li class='pass'>\n";
         echo "<span>Passed</span> ";
         echo "<br />" . $this->_htmlEntities($test->getName()) . " ({$time} seconds)\n";
         echo "</li>\n";
     }
 }
Exemple #24
0
 /**
  * A test ended.
  *
  * @param  PHPUnit_Framework_Test $test
  * @param  float                  $time
  */
 public function endTest(PHPUnit_Framework_Test $test, $time)
 {
     $this->log->info(sprintf('Test "%s" ended.', $test->getName()));
 }
Exemple #25
0
 /**
  * A test started.
  *
  * @param PHPUnit_Framework_Test $test
  */
 public function startTest(PHPUnit_Framework_Test $test)
 {
     $testCase = $this->document->createElement('testcase');
     $testCase->setAttribute('name', $test->getName());
     if ($test instanceof PHPUnit_Framework_TestCase) {
         $class = new ReflectionClass($test);
         $methodName = $test->getName();
         if ($class->hasMethod($methodName)) {
             $method = $class->getMethod($test->getName());
             $testCase->setAttribute('class', $class->getName());
             $testCase->setAttribute('file', $class->getFileName());
             $testCase->setAttribute('line', $method->getStartLine());
         }
     }
     $this->currentTestCase = $testCase;
 }
Exemple #26
0
 /**
  * A test has ended.
  *
  * @param PHPUnit_Framework_Test $test the test that has ended
  * @param float $time ?
  *
  * @return void
  */
 public function endTest(PHPUnit_Framework_Test $test, $time)
 {
     $this->memoryUsageEndOfTest = memory_get_usage();
     if ($test instanceof PHPUnit_Framework_TestCase) {
         /** @var  PHPUnit_Framework_TestCase $test */
         // Tests with the same name are a sign of data provider usage.
         $testNameParts = explode(' ', $test->getName());
         $testName = get_class($test) . ':' . $testNameParts[0];
         if ($testName !== $this->previousTestName) {
             $this->currentDataProviderNumber = 0;
             $this->currentTestNumber++;
             $this->previousTestName = $testName;
         } else {
             $this->currentDataProviderNumber++;
             $this->totalNumberOfDetectedDataProviderTests++;
         }
     }
     if ($this->totalNumberOfTests - $this->totalNumberOfDetectedDataProviderTests > 0) {
         $percentDone = 100.0 * $this->currentTestNumber / ($this->totalNumberOfTests - $this->totalNumberOfDetectedDataProviderTests);
     } else {
         $percentDone = 0.0;
     }
     if ($test instanceof PHPUnit_Framework_TestCase) {
         $this->testAssertions += $test->getNumAssertions();
     }
     $output = '</div>';
     if ($this->showTime) {
         $output .= '<span class="time-usages small-font"><strong>Time:</strong> ' . sprintf('%.4f', $time) . ' sec.</span><br />';
     }
     $output .= '</div>' . '<script type="text/javascript">/*<![CDATA[*/document.getElementById("progress-bar").style.width = "' . $percentDone . '%";/*]]>*/</script>';
     $this->outputService->output($output);
     $this->outputService->flushOutputBuffer();
 }
 /**
  * end test
  * 
  * (non-PHPdoc)
  * @see PHPUnit_Framework_TestListener::endTest()
  */
 public function endTest(PHPUnit_Framework_Test $test, $time)
 {
     Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' [PHPUnit] End test: ' . $test->getName() . ' / Time: ' . $time);
 }
 /**
  * A test ended.
  *
  * @param  PHPUnit_Framework_Test $test
  * @param  float                  $time
  * @access public
  */
 public function endTest(PHPUnit_Framework_Test $test, $time)
 {
     $this->testEnded($test->getName());
 }
Exemple #29
0
 /**
  * A test ended.
  *
  * @param  PHPUnit_Framework_Test $test
  * @param  float                  $time
  */
 public function endTest(PHPUnit_Framework_Test $test, $time)
 {
     if (!$test instanceof PHPUnit_Framework_Warning) {
         if ($test->getStatus() == PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) {
             $ifStatus = array('assigned', 'new', 'reopened');
             $newStatus = 'closed';
             $message = 'Automatically closed by PHPUnit (test passed).';
             $resolution = 'fixed';
             $cumulative = TRUE;
         } else {
             if ($test->getStatus() == PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE) {
                 $ifStatus = array('closed');
                 $newStatus = 'reopened';
                 $message = 'Automatically reopened by PHPUnit (test failed).';
                 $resolution = '';
                 $cumulative = FALSE;
             } else {
                 return;
             }
         }
         $name = $test->getName();
         $tickets = PHPUnit_Util_Test::getTickets(get_class($test), $name);
         foreach ($tickets as $ticket) {
             // Remove this test from the totals (if it passed).
             if ($test->getStatus() == PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) {
                 unset($this->ticketCounts[$ticket][$name]);
             }
             // Only close tickets if ALL referenced cases pass
             // but reopen tickets if a single test fails.
             if ($cumulative) {
                 // Determine number of to-pass tests:
                 if (count($this->ticketCounts[$ticket]) > 0) {
                     // There exist remaining test cases with this reference.
                     $adjustTicket = FALSE;
                 } else {
                     // No remaining tickets, go ahead and adjust.
                     $adjustTicket = TRUE;
                 }
             } else {
                 $adjustTicket = TRUE;
             }
             if ($adjustTicket && in_array($ticketInfo[3]['status'], $ifStatus)) {
                 $this->updateTicket($ticket, $newStatus, $message, $resolution);
             }
         }
     }
 }
Exemple #30
0
 /**
  * A test ended.
  *
  * @param  PHPUnit_Framework_Test $test
  * @param  float                  $time
  * @access public
  */
 public function endTest(PHPUnit_Framework_Test $test, $time)
 {
     $prettifiedName = $this->prettifier->prettifyTestMethod($test->getName());
     if (!isset($this->tests[$prettifiedName])) {
         if (!$this->testFailed) {
             $this->tests[$prettifiedName]['success'] = 1;
             $this->tests[$prettifiedName]['failure'] = 0;
         } else {
             $this->tests[$prettifiedName]['success'] = 0;
             $this->tests[$prettifiedName]['failure'] = 1;
         }
     } else {
         if (!$this->testFailed) {
             $this->tests[$prettifiedName]['success']++;
         } else {
             $this->tests[$prettifiedName]['failure']++;
         }
     }
 }