Author: Sebastian Bergmann (sb@sebastian-bergmann.de)
Exemple #1
0
 public function doEnhancedRun(\PHPUnit_Framework_Test $suite, \PHPUnit_Framework_TestResult $result, array $arguments = [])
 {
     unset($GLOBALS['app']);
     // hook for not to serialize globals
     $this->handleConfiguration($arguments);
     $result->convertErrorsToExceptions(false);
     if (empty(self::$persistentListeners)) {
         $this->applyReporters($result, $arguments);
     }
     $arguments['listeners'][] = $this->printer;
     // clean up listeners between suites
     foreach ($arguments['listeners'] as $listener) {
         $result->addListener($listener);
     }
     $filterFactory = new \PHPUnit_Runner_Filter_Factory();
     if ($arguments['groups']) {
         $filterFactory->addFilter(new \ReflectionClass('PHPUnit_Runner_Filter_Group_Include'), $arguments['groups']);
     }
     if ($arguments['excludeGroups']) {
         $filterFactory->addFilter(new \ReflectionClass('PHPUnit_Runner_Filter_Group_Exclude'), $arguments['excludeGroups']);
     }
     if ($arguments['filter']) {
         $filterFactory->addFilter(new \ReflectionClass('PHPUnit_Runner_Filter_Test'), $arguments['filter']);
     }
     $suite->injectFilter($filterFactory);
     $suite->run($result);
     unset($suite);
     foreach ($arguments['listeners'] as $listener) {
         $result->removeListener($listener);
     }
     return $result;
 }
Exemple #2
0
 public function groupsForTest(\PHPUnit_Framework_Test $test)
 {
     $groups = [];
     if ($test instanceof ScenarioDriven) {
         $groups = $test->getScenario()->getGroups();
     }
     if ($test instanceof Reported) {
         $info = $test->getReportFields();
         if (isset($info['class'])) {
             $groups = array_merge($groups, \PHPUnit_Util_Test::getGroups($info['class'], $info['name']));
         }
         $filename = $info['file'];
     } else {
         $groups = array_merge($groups, \PHPUnit_Util_Test::getGroups(get_class($test), $test->getName(false)));
         $filename = (new \ReflectionClass($test))->getFileName();
     }
     foreach ($this->testsInGroups as $group => $tests) {
         foreach ($tests as $testPattern) {
             if ($filename == $testPattern) {
                 $groups[] = $group;
             }
             if (strpos($filename . ':' . $test->getName(false), $testPattern) === 0) {
                 $groups[] = $group;
             }
         }
     }
     return array_unique($groups);
 }
 public function endTest(PHPUnit_Framework_Test $test, $time)
 {
     if (!$test->hasFailed()) {
         $this->logger->write('OK', SeleniumTestSuite::RESULT_OK);
         $this->tests_ok++;
     }
 }
Exemple #4
0
 public function endTest(PHPUnit_Framework_Test $test, $time)
 {
     $this->tests++;
     switch ($test->getStatus()) {
         case PHPUnit_Runner_BaseTestRunner::STATUS_PASSED:
             echo '.';
             break;
         case PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE:
             echo 'F';
             break;
         case PHPUnit_Runner_BaseTestRunner::STATUS_ERROR:
             echo 'E';
             break;
         case PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE:
             echo 'I';
             break;
         case PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED:
             echo 'S';
             break;
     }
     if ($this->tests % 60 == 0) {
         echo "\n";
     }
     $this->totalTime += $time;
 }
Exemple #5
0
 public function endTest(\PHPUnit_Framework_Test $test, $time)
 {
     if ($test instanceof \Codeception\TestCase\Cept) {
         $this->currentTestCase->setAttribute('name', $test->toString());
     }
     return parent::endTest($test, $time);
 }
 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);
 }
Exemple #7
0
 public function endTest(\PHPUnit_Framework_Test $test, $time)
 {
     if ($test instanceof \PHPUnit_Framework_TestCase) {
         $this->numAssertions += $test->getNumAssertions();
     }
     $this->lastTestFailed = false;
 }
Exemple #8
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);
    }
Exemple #9
0
 /**
  * endTest is called after each test and checks if \Mockery::close() has
  * been called, and will let the test fail if it hasn't.
  *
  * @param  PHPUnit_Framework_Test $test
  * @param  float                  $time
  */
 public function endTest(\PHPUnit_Framework_Test $test, $time)
 {
     if (!$test instanceof \PHPUnit_Framework_TestCase) {
         // We need the getTestResultObject and getStatus methods which are
         // not part of the interface.
         return;
     }
     if ($test->getStatus() !== \PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) {
         // If the test didn't pass there is no guarantee that
         // verifyMockObjects and assertPostConditions have been called.
         // And even if it did, the point here is to prevent false
         // negatives, not to make failing tests fail for more reasons.
         return;
     }
     try {
         // The self() call is used as a sentinel. Anything that throws if
         // the container is closed already will do.
         \Mockery::self();
     } catch (\LogicException $_) {
         return;
     }
     $e = new \PHPUnit_Framework_ExpectationFailedException(sprintf("Mockery's expectations have not been verified. Make sure that \\Mockery::close() is called at the end of the test. Consider using %s\\MockeryPHPUnitIntegration or extending %s\\MockeryTestCase.", __NAMESPACE__, __NAMESPACE__));
     $result = $test->getTestResultObject();
     $result->addFailure($test, $e, $time);
 }
Exemple #10
0
 public function doEnhancedRun(\PHPUnit_Framework_Test $suite, \PHPUnit_Framework_TestResult $result, array $arguments = array())
 {
     unset($GLOBALS['app']);
     // hook for not to serialize globals
     $arguments = array_merge($this->defaultArguments, $arguments);
     $this->handleConfiguration($arguments);
     $result->convertErrorsToExceptions(false);
     if ($arguments['report']) {
         $this->printer = new Report();
     }
     if (empty(self::$persistentListeners)) {
         $this->applyReporters($result, $arguments);
     }
     $arguments['listeners'][] = $this->printer;
     // clean up listeners between suites
     foreach ($arguments['listeners'] as $listener) {
         $result->addListener($listener);
     }
     $suite->run($result, $arguments['filter'], $arguments['groups'], $arguments['excludeGroups'], $arguments['processIsolation']);
     unset($suite);
     foreach ($arguments['listeners'] as $listener) {
         $result->removeListener($listener);
     }
     return $result;
 }
 /**
  * @param PHPUnit_Framework_Test $test
  * @param array                  $groups
  */
 public function addTest(PHPUnit_Framework_Test $test, $groups = array())
 {
     if ($test instanceof PHPUnit_Framework_Warning && preg_match('/^No tests found in class/', $test->getMessage())) {
         return;
     }
     parent::addTest($test, $groups);
 }
 public function endTest(PHPUnit_Framework_Test $test, $time)
 {
     // copied from parent:endTest()
     if ($test instanceof PHPUnit_Framework_TestCase) {
         $this->numAssertions += $test->getNumAssertions();
     } else {
         if ($test instanceof PHPUnit_Extensions_PhptTestCase) {
             $this->numAssertions++;
         }
     }
     $this->lastTestFailed = false;
     // custom printing code
     if (get_class($test) == 'PHPUnit_Framework_TestSuite') {
         // this occurs when the test suite setup has thrown an error
         $this->out(" SETUP FAIL", 'fg-red', true);
     } elseif ($test->hasFailed()) {
         $this->out(" FAIL", 'fg-red', true);
     } else {
         $numAssertions = $test instanceof PHPUnit_Framework_TestCase ? $test->getNumAssertions() : 1;
         if ($numAssertions > 0) {
             $this->out(' OK (' . $numAssertions . ' assertions)', 'fg-green', true);
         } else {
             $this->out(' SKIPPED (0 assertions)', 'fg-yellow', true);
         }
     }
 }
 public function endTest(Test $test, $time)
 {
     $this->currentTest = null;
     if ($test instanceof TestCase && $test->getStatus() === TestRunner::STATUS_PASSED) {
         $this->storage->record($this->run, $test, $time, StorageInterface::STATUS_PASSED);
     }
 }
Exemple #14
0
 public function endTest(\PHPUnit_Framework_Test $test, $time)
 {
     if ($test instanceof Spec\TestCaseInterface) {
         $levels = 0;
         if ($parent = $test->getSuite()) {
             while ($parent = $parent->getParent()) {
                 $levels++;
             }
         }
         $output = str_repeat("  ", $levels) . $test->getTitle();
         if ($this->lastTestResult !== self::PASSED) {
             switch ($this->lastTestResult) {
                 case self::FAILED:
                     $output .= ' (FAILED - ' . count($this->exceptions) . ')';
                     $output = "{$output}";
                     break;
                 case self::ERROR:
                     $output .= ' (ERROR - ' . count($this->exceptions) . ')';
                     $output = "{$output}";
                     break;
                 case self::INCOMPLETE:
                     $output .= ' (INCOMPLETE)';
                     $output = "{$output}";
                     break;
                 case self::SKIPPED:
                     $output .= ' (SKIPPED)';
                     $output = "{$output}";
                     break;
             }
         } else {
             $output = "" . $output . "";
         }
         $this->write($output . PHP_EOL);
     }
 }
Exemple #15
0
 public function endTest(\PHPUnit_Framework_Test $test, $time)
 {
     $steps = [];
     $success = $this->testStatus == \PHPUnit_Runner_BaseTestRunner::STATUS_PASSED;
     if ($success) {
         $this->successful++;
     }
     if ($test instanceof ScenarioDriven) {
         $steps = $test->getScenario()->getSteps();
     }
     $this->timeTaken += $time;
     switch ($this->testStatus) {
         case \PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE:
             $scenarioStatus = 'scenarioFailed';
             break;
         case \PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED:
             $scenarioStatus = 'scenarioSkipped';
             break;
         case \PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE:
             $scenarioStatus = 'scenarioIncomplete';
             break;
         case \PHPUnit_Runner_BaseTestRunner::STATUS_ERROR:
             $scenarioStatus = 'scenarioFailed';
             break;
         default:
             $scenarioStatus = 'scenarioSuccess';
     }
     $stepsBuffer = '';
     $metaStep = null;
     $subStepsBuffer = '';
     foreach ($steps as $step) {
         /** @var $step Step  **/
         if ($step->getMetaStep()) {
             $subStepsBuffer .= $this->renderStep($step);
             $metaStep = $step->getMetaStep();
             continue;
         }
         if ($step->getMetaStep() != $metaStep) {
             $stepsBuffer .= $this->renderSubsteps($metaStep, $subStepsBuffer);
             $subStepsBuffer = '';
         }
         $metaStep = $step->getMetaStep();
         $stepsBuffer .= $this->renderStep($step);
     }
     if ($subStepsBuffer and $metaStep) {
         $stepsBuffer .= $this->renderSubsteps($metaStep, $subStepsBuffer);
     }
     $scenarioTemplate = new \Text_Template($this->templatePath . 'scenario.html');
     $failure = '';
     $name = Descriptor::getTestSignature($test);
     if (isset($this->failures[$name])) {
         $failTemplate = new \Text_Template($this->templatePath . 'fail.html');
         $failTemplate->setVar(['fail' => nl2br($this->failures[$name])]);
         $failure = $failTemplate->render();
     }
     $toggle = $stepsBuffer ? '<span class="toggle">+</span>' : '';
     $scenarioTemplate->setVar(['id' => ++$this->id, 'name' => ucfirst(Descriptor::getTestAsString($test)), 'scenarioStatus' => $scenarioStatus, 'steps' => $stepsBuffer, 'toggle' => $toggle, 'failure' => $failure, 'time' => round($time, 2)]);
     $this->scenarios .= $scenarioTemplate->render();
 }
 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');
 }
 /**
  * @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));
     }
 }
Exemple #19
0
 /**
  * After each test, perform Mockery verification tasks and cleanup the
  * statically stored Mockery container for the next test.
  *
  * @param  PHPUnit_Framework_Test $test
  * @param  float                  $time
  */
 public function endTest(\PHPUnit_Framework_Test $test, $time)
 {
     try {
         \Mockery::close();
     } catch (\Exception $e) {
         $result = $test->getTestResultObject();
         $result->addError($test, $e, $time);
     }
 }
Exemple #20
0
 public function endTest(\PHPUnit_Framework_Test $test, $time)
 {
     if ($this->attachCurrentTestCase and $test instanceof Test) {
         $numAssertions = $test->getNumAssertions();
         $this->testSuiteAssertions[$this->testSuiteLevel] += $numAssertions;
         $this->currentTestCase->setAttribute('assertions', $numAssertions);
     }
     parent::endTest($test, $time);
 }
 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;
 }
 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));
     }
 }
 private function printTestdox(PHPUnit_Framework_Test $test, $char)
 {
     if ($test instanceof Zoetrope_SeleniumTestCase) {
         /* @var $test Zoetrope_SeleniumTestCase */
         $test_name = $test->getNameHumanReadable();
     } else {
         $test_name = 'Unknown test in ' . get_class($test);
     }
     echo '[' . $char . '] ' . $test_name . chr(10);
 }
 /**
  * {@inheritdoc}
  */
 public function startTest(\PHPUnit_Framework_Test $test)
 {
     // print_r(get_class_methods($test)); die;
     $this->error = false;
     $this->mockLogger = $test->getMockLogger();
     $this->testFullName = sprintf('%s::%s', get_class($test), $test->getName());
     $this->mockLogger->expects($test->any())->method('log')->will($test->returnCallback(function ($level, $message, $context) {
         $this->log[$this->testFullName][] = ['level' => $level, 'message' => $message, 'context' => $context];
     }));
 }
 public function startTest(PHPUnit_Framework_Test $test)
 {
     if ($this->_verbose) {
         echo date('Y-m-d H:i:s') . ': starting ' . $test->toString() . "\n\n";
     }
     if ($this->_getProgressBar()) {
         //erstellt sie beim ersten aufruf, nicht im kostruktor machen da sonst zu früh was rausgeschrieben wird
         $this->writeProgress('.');
     }
     return parent::startTest($test);
 }
 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>';
 }
 /**
  * @param PHPUnit_Framework_Test $test
  * @param float $time
  */
 public function endTest(\PHPUnit_Framework_Test $test, $time)
 {
     try {
         if ($test instanceof \PHPUnit_Framework_TestCase) {
             $test->addToAssertionCount(MatcherAssert::getCount());
         }
     } catch (\Exception $e) {
         $result = $test->getTestResultObject();
         $result->addError($test, $e, $time);
     }
 }
Exemple #28
0
 /**
  * A test ended.
  *
  * @param  PHPUnit_Framework_Test $test
  * @param  float                  $time
  */
 public function endTest(PHPUnit_Framework_Test $test, $time)
 {
     if ($test instanceof PHPUnit_Extensions_Story_TestCase || $test instanceof PHPUnit_Extensions_Story_SeleniumTestCase) {
         if ($this->testStatus == PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) {
             $this->successful++;
             $success = TRUE;
         } else {
             $success = FALSE;
         }
         $this->onTest($this->currentTestMethodPrettified, $success, $test->getScenario()->getSteps());
     }
 }
Exemple #29
0
 /**
  * Constructs a TestFailure with the given test and exception.
  *
  * @param PHPUnit_Framework_Test $failedTest
  * @param Exception $thrownException
  */
 public function __construct(PHPUnit_Framework_Test $failedTest, Exception $thrownException)
 {
     if ($failedTest instanceof PHPUnit_Framework_SelfDescribing) {
         $this->testName = $failedTest->toString();
     } else {
         $this->testName = get_class($failedTest);
     }
     if (!$failedTest instanceof PHPUnit_Framework_TestCase || !$failedTest->isInIsolation()) {
         $this->failedTest = $failedTest;
     }
     $this->thrownException = $thrownException;
 }
Exemple #30
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__);
 }