/**
  * @access protected
  */
 protected function runTest()
 {
     PHPUnit_Util_Timer::start();
     parent::runTest();
     $time = PHPUnit_Util_Timer::stop();
     if ($this->maxRunningTime != 0 && $time > $this->maxRunningTime) {
         $this->fail(sprintf('expected running time: <= %s but was: %s', $this->maxRunningTime, $time));
     }
 }
 public function testSecondsToTimeString()
 {
     $this->assertEquals('0 seconds', PHPUnit_Util_Timer::secondsToTimeString(0));
     $this->assertEquals('1 second', PHPUnit_Util_Timer::secondsToTimeString(1));
     $this->assertEquals('2 seconds', PHPUnit_Util_Timer::secondsToTimeString(2));
     $this->assertEquals('01:00', PHPUnit_Util_Timer::secondsToTimeString(60));
     $this->assertEquals('01:01', PHPUnit_Util_Timer::secondsToTimeString(61));
     $this->assertEquals('02:00', PHPUnit_Util_Timer::secondsToTimeString(120));
     $this->assertEquals('02:01', PHPUnit_Util_Timer::secondsToTimeString(121));
     $this->assertEquals('01:00:00', PHPUnit_Util_Timer::secondsToTimeString(3600));
     $this->assertEquals('01:00:01', PHPUnit_Util_Timer::secondsToTimeString(3601));
 }
 public function testPersistentResourceSimulation()
 {
     PHPUnit_Util_Timer::start();
     $movie = new ffmpeg_movie(self::$moviePath, true);
     $movie = new ffmpeg_movie(self::$moviePath, true);
     $movie = new ffmpeg_movie(self::$moviePath, true);
     $elapsed = PHPUnit_Util_Timer::stop();
     PHPUnit_Util_Timer::start();
     $movie = new ffmpeg_movie(self::$moviePath);
     $movie = new ffmpeg_movie(self::$moviePath);
     $movie = new ffmpeg_movie(self::$moviePath);
     $elapsed1 = PHPUnit_Util_Timer::stop();
     $this->assertGreaterThan($elapsed, $elapsed1, 'Persistent resource simulation should be faster');
 }
 public function run(PHPUnit_Framework_TestResult $result = null)
 {
     PHPUnit_Framework_Assert::resetCount();
     if ($result === NULL) {
         $result = new PHPUnit_Framework_TestResult();
     }
     $this->suite->publishTestArticles();
     // Add articles needed by the tests.
     $backend = new ParserTestSuiteBackend();
     $result->startTest($this);
     // Support the transition to PHPUnit 3.5 where PHPUnit_Util_Timer is replaced with PHP_Timer
     if (class_exists('PHP_Timer')) {
         PHP_Timer::start();
     } else {
         PHPUnit_Util_Timer::start();
     }
     $r = false;
     try {
         # Run the test.
         # On failure, the subclassed backend will throw an exception with
         # the details.
         $pt = new PHPUnitParserTest();
         $r = $pt->runTest($this->test['test'], $this->test['input'], $this->test['result'], $this->test['options'], $this->test['config']);
     } catch (PHPUnit_Framework_AssertionFailedError $e) {
         // PHPUnit_Util_Timer -> PHP_Timer support (see above)
         if (class_exists('PHP_Timer')) {
             $result->addFailure($this, $e, PHP_Timer::stop());
         } else {
             $result->addFailure($this, $e, PHPUnit_Util_Timer::stop());
         }
     } catch (Exception $e) {
         // PHPUnit_Util_Timer -> PHP_Timer support (see above)
         if (class_exists('PHP_Timer')) {
             $result->addFailure($this, $e, PHP_Timer::stop());
         } else {
             $result->addFailure($this, $e, PHPUnit_Util_Timer::stop());
         }
     }
     // PHPUnit_Util_Timer -> PHP_Timer support (see above)
     if (class_exists('PHP_Timer')) {
         $result->endTest($this, PHP_Timer::stop());
     } else {
         $result->endTest($this, PHPUnit_Util_Timer::stop());
     }
     $backend->recorder->record($this->test['test'], $r);
     $this->addToAssertionCount(PHPUnit_Framework_Assert::getCount());
     return $result;
 }
Exemple #5
0
 /**
  * Runs a TestCase.
  *
  * @param  PHPUnit_Framework_Test $test
  */
 public function run(PHPUnit_Framework_Test $test)
 {
     PHPUnit_Framework_Assert::resetCount();
     $error = FALSE;
     $failure = FALSE;
     $this->startTest($test);
     $errorHandlerSet = FALSE;
     if ($this->convertErrorsToExceptions) {
         $oldErrorHandler = set_error_handler(array('PHPUnit_Util_ErrorHandler', 'handleError'), E_ALL | E_STRICT);
         if ($oldErrorHandler === NULL) {
             $errorHandlerSet = TRUE;
         } else {
             restore_error_handler();
         }
     }
     if (self::$xdebugLoaded === NULL) {
         self::$xdebugLoaded = extension_loaded('xdebug');
         self::$useXdebug = self::$xdebugLoaded;
     }
     $useXdebug = self::$useXdebug && $this->collectCodeCoverageInformation && !$test instanceof PHPUnit_Extensions_SeleniumTestCase;
     if ($useXdebug) {
         xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
     }
     PHPUnit_Util_Timer::start();
     try {
         $test->runBare();
     } catch (PHPUnit_Framework_AssertionFailedError $e) {
         $failure = TRUE;
     } catch (Exception $e) {
         $error = TRUE;
     }
     $time = PHPUnit_Util_Timer::stop();
     if ($useXdebug) {
         $codeCoverage = xdebug_get_code_coverage();
         xdebug_stop_code_coverage();
         $this->appendCodeCoverageInformation($test, $codeCoverage);
     }
     if ($errorHandlerSet === TRUE) {
         restore_error_handler();
     }
     $test->addToAssertionCount(PHPUnit_Framework_Assert::getCount());
     if ($error === TRUE) {
         $this->addError($test, $e, $time);
     } else {
         if ($failure === TRUE) {
             $this->addFailure($test, $e, $time);
         }
     }
     $this->endTest($test, $time);
 }
 /**
  * @param float $timeElapsed
  */
 protected function printHeader($timeElapsed)
 {
     if (isset($_SERVER['REQUEST_TIME'])) {
         $timeElapsed = PHPUnit_Util_Timer::secondsToTimeString(time() - $_SERVER['REQUEST_TIME']);
     } else {
         $timeElapsed = PHPUnit_Util_Timer::secondsToTimeString($timeElapsed);
     }
     if (function_exists('memory_get_peak_usage')) {
         $memory = sprintf(', Memory: %4.2fMb', memory_get_peak_usage(TRUE) / 1048576);
     } else {
         $memory = '';
     }
     $this->write(sprintf("%sTime: %s%s\n\n", $this->verbose ? "\n" : "\n\n", $timeElapsed, $memory));
 }
 /**
  * @param  float   $timeElapsed
  * @access protected
  */
 protected function printHeader($timeElapsed)
 {
     $this->write("\n\nTime: " . PHPUnit_Util_Timer::secondsToTimeString($timeElapsed) . "\n\n");
 }
 /**
  * Runs a test and collects its result in a TestResult instance.
  *
  * @param  PHPUnit_Framework_TestResult $result
  * @param  array $options Array with ini settings for the php instance run,
  *                        key being the name if the setting, value the ini value.
  * @return PHPUnit_Framework_TestResult
  * @access public
  */
 public function run(PHPUnit_Framework_TestResult $result = NULL, $options = array())
 {
     if (!class_exists('PEAR_RunTest', FALSE)) {
         throw new RuntimeException('Class PEAR_RunTest not found.');
     }
     if ($result === NULL) {
         $result = new PHPUnit_Framework_TestResult();
     }
     if (!is_array($options)) {
         throw new InvalidArgumentException();
     }
     $options = array_merge($options, $this->options);
     $coverage = $result->getCollectCodeCoverageInformation();
     if ($coverage) {
         $options = array('coverage' => TRUE);
     } else {
         $options = array();
     }
     $runner = new PEAR_RunTest(new PHPUnit_Extensions_PhptTestCase_Logger(), $options);
     if ($coverage) {
         $runner->xdebug_loaded = TRUE;
     } else {
         $runner->xdebug_loaded = FALSE;
     }
     $result->startTest($this);
     PHPUnit_Util_Timer::start();
     $buffer = $runner->run($this->filename, $options);
     $time = PHPUnit_Util_Timer::stop();
     $base = basename($this->filename);
     $path = dirname($this->filename);
     $coverageFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.xdebug', $base);
     $diffFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.diff', $base);
     $expFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.exp', $base);
     $logFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.log', $base);
     $outFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.out', $base);
     $phpFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.php', $base);
     if (is_object($buffer) && $buffer instanceof PEAR_Error) {
         $result->addError($this, new RuntimeException($buffer->getMessage()), $time);
     } else {
         if ($buffer == 'SKIPPED') {
             $result->addFailure($this, new PHPUnit_Framework_SkippedTestError(), 0);
         } else {
             if ($buffer != 'PASSED') {
                 $result->addFailure($this, PHPUnit_Framework_ComparisonFailure::diffEqual(file_get_contents($expFile), file_get_contents($outFile), FALSE, $this->getName()), $time);
             }
         }
     }
     foreach (array($diffFile, $expFile, $logFile, $phpFile, $outFile) as $file) {
         if (file_exists($file)) {
             unlink($file);
         }
     }
     if ($coverage) {
         eval('$coverageData = ' . file_get_contents($coverageFile) . ';');
         unset($coverageData[$phpFile]);
         $codeCoverageInformation = array('test' => $this, 'files' => $coverageData);
         $result->appendCodeCoverageInformation($this, $codeCoverageInformation);
         unlink($coverageFile);
     }
     $result->endTest($this, $time);
     return $result;
 }
Exemple #9
0
 /**
  * Runs a test and collects its result in a TestResult instance.
  *
  * @param  PHPUnit_Framework_TestResult $result
  * @param  array                        $options
  * @return PHPUnit_Framework_TestResult
  */
 public function run(PHPUnit_Framework_TestResult $result = NULL, array $options = array())
 {
     if (!class_exists('PEAR_RunTest', FALSE)) {
         throw new PHPUnit_Framework_Exception('Class PEAR_RunTest not found.');
     }
     if (isset($GLOBALS['_PEAR_destructor_object_list']) && is_array($GLOBALS['_PEAR_destructor_object_list']) && !empty($GLOBALS['_PEAR_destructor_object_list'])) {
         $pearDestructorObjectListCount = count($GLOBALS['_PEAR_destructor_object_list']);
     } else {
         $pearDestructorObjectListCount = 0;
     }
     if ($result === NULL) {
         $result = new PHPUnit_Framework_TestResult();
     }
     $coverage = $result->getCollectCodeCoverageInformation();
     $options = array_merge($options, $this->options);
     if (!isset($options['include_path'])) {
         $options['include_path'] = get_include_path();
     }
     if ($coverage) {
         $options['coverage'] = TRUE;
     } else {
         $options['coverage'] = FALSE;
     }
     $currentErrorReporting = error_reporting(E_ERROR | E_WARNING | E_PARSE);
     $runner = new PEAR_RunTest(new PHPUnit_Extensions_PhptTestCase_Logger(), $options);
     if ($coverage) {
         $runner->xdebug_loaded = TRUE;
     } else {
         $runner->xdebug_loaded = FALSE;
     }
     $result->startTest($this);
     PHPUnit_Util_Timer::start();
     $buffer = $runner->run($this->filename, $options);
     $time = PHPUnit_Util_Timer::stop();
     error_reporting($currentErrorReporting);
     $base = basename($this->filename);
     $path = dirname($this->filename);
     $coverageFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.xdebug', $base);
     $diffFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.diff', $base);
     $expFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.exp', $base);
     $logFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.log', $base);
     $outFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.out', $base);
     $phpFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.php', $base);
     if (file_exists($phpFile)) {
         PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist($phpFile, 'TESTS');
     }
     if (is_object($buffer) && $buffer instanceof PEAR_Error) {
         $result->addError($this, new RuntimeException($buffer->getMessage()), $time);
     } else {
         if ($buffer == 'SKIPPED') {
             $result->addFailure($this, new PHPUnit_Framework_SkippedTestError(), 0);
         } else {
             if ($buffer != 'PASSED') {
                 $result->addFailure($this, PHPUnit_Framework_ComparisonFailure::diffEqual(file_get_contents($expFile), file_get_contents($outFile)), $time);
             }
         }
     }
     foreach (array($diffFile, $expFile, $logFile, $phpFile, $outFile) as $file) {
         if (file_exists($file)) {
             unlink($file);
         }
     }
     if ($coverage && file_exists($coverageFile)) {
         eval('$coverageData = ' . file_get_contents($coverageFile) . ';');
         unset($coverageData[$phpFile]);
         $result->getCodeCoverage()->append($coverageData, $this);
         unlink($coverageFile);
     }
     $result->endTest($this, $time);
     // Do not invoke PEAR's destructor mechanism for PHP 4
     // as it raises an E_STRICT.
     if ($pearDestructorObjectListCount == 0) {
         unset($GLOBALS['_PEAR_destructor_object_list']);
     } else {
         $count = count($GLOBALS['_PEAR_destructor_object_list']) - $pearDestructorObjectListCount;
         for ($i = 0; $i < $count; $i++) {
             array_pop($GLOBALS['_PEAR_destructor_object_list']);
         }
     }
     return $result;
 }
 /**
  * @param  float   $timeElapsed
  */
 protected function printHeader($timeElapsed)
 {
     $this->write(sprintf("%sTime: %s\n\n", $this->verbose ? "\n" : "\n\n", PHPUnit_Util_Timer::secondsToTimeString($timeElapsed)));
 }
 public function run(PHPUnit_Framework_TestResult $result = NULL)
 {
     PHPUnit_Framework_Assert::resetCount();
     if ($result === NULL) {
         $result = new PHPUnit_Framework_TestResult();
     }
     $t = MediaWikiParserTestSuite::$iter->current();
     $k = MediaWikiParserTestSuite::$iter->key();
     if (!MediaWikiParserTestSuite::$iter->valid()) {
         return;
     }
     // The only way this should happen is if the parserTest.txt
     // file were modified while the script is running.
     if ($k != $this->number) {
         $i = $this->number;
         wfDie("I got confused!\n");
     }
     $result->startTest($this);
     PHPUnit_Util_Timer::start();
     $r = false;
     try {
         $r = MediaWikiParserTestSuite::$parser->runTest($t['test'], $t['input'], $t['result'], $t['options'], $t['config']);
         PHPUnit_Framework_Assert::assertTrue(true, $t['test']);
     } catch (PHPUnit_Framework_AssertionFailedError $e) {
         $result->addFailure($this, $e, PHPUnit_Util_Timer::stop());
     } catch (Exception $e) {
         $result->addError($this, $e, PHPUnit_Util_Timer::stop());
     }
     PHPUnit_Framework_Assert::assertTrue(true, $t['test']);
     $result->endTest($this, PHPUnit_Util_Timer::stop());
     MediaWikiParserTestSuite::$parser->recorder->record($t['test'], $r);
     MediaWikiParserTestSuite::$iter->next();
     $this->addToAssertionCount(PHPUnit_Framework_Assert::getCount());
     return $result;
 }
Exemple #12
0
 /**
  * Runs a TestCase.
  *
  * @param  PHPUnit_Framework_Test $test
  * @access public
  */
 public function run(PHPUnit_Framework_Test $test)
 {
     $error = FALSE;
     $failure = FALSE;
     $this->startTest($test);
     $errorHandlerSet = FALSE;
     if (self::$isPHP52 === NULL) {
         if (version_compare(phpversion(), '5.2.0RC1', '>=')) {
             self::$isPHP52 = TRUE;
         } else {
             self::$isPHP52 = FALSE;
         }
     }
     if (self::$isPHP52) {
         $oldErrorHandler = set_error_handler('PHPUnit_Util_ErrorHandler', E_RECOVERABLE_ERROR | E_USER_ERROR | E_NOTICE | E_STRICT);
     } else {
         $oldErrorHandler = set_error_handler('PHPUnit_Util_ErrorHandler', E_USER_ERROR | E_NOTICE | E_STRICT);
     }
     if ($oldErrorHandler === NULL) {
         $errorHandlerSet = TRUE;
     } else {
         restore_error_handler();
     }
     if (self::$xdebugLoaded === NULL) {
         self::$xdebugLoaded = extension_loaded('xdebug');
         self::$useXdebug = self::$xdebugLoaded;
     }
     $useXdebug = self::$useXdebug && $this->collectCodeCoverageInformation && !$test instanceof PHPUnit_Extensions_SeleniumTestCase;
     if ($useXdebug) {
         xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
     }
     PHPUnit_Util_Timer::start();
     try {
         $test->runBare();
     } catch (PHPUnit_Framework_AssertionFailedError $e) {
         $failure = TRUE;
     } catch (Exception $e) {
         $error = TRUE;
     }
     $time = PHPUnit_Util_Timer::stop();
     if ($useXdebug) {
         $this->codeCoverageInformation[] = array('test' => $test, 'files' => xdebug_get_code_coverage());
         xdebug_stop_code_coverage();
     }
     if ($errorHandlerSet === TRUE) {
         restore_error_handler();
     }
     if ($error === TRUE) {
         $this->addError($test, $e, $time);
     } else {
         if ($failure === TRUE) {
             $this->addFailure($test, $e, $time);
         }
     }
     $this->endTest($test, $time);
     $this->time += $time;
 }
Exemple #13
0
 /**
  * Runs a TestCase.
  *
  * @param  PHPUnit_Framework_Test $test
  */
 public function run(PHPUnit_Framework_Test $test)
 {
     PHPUnit_Framework_Assert::resetCount();
     $error = FALSE;
     $failure = FALSE;
     $this->startTest($test);
     $errorHandlerSet = FALSE;
     if ($this->convertErrorsToExceptions) {
         $oldErrorHandler = set_error_handler(array('PHPUnit_Util_ErrorHandler', 'handleError'), E_ALL | E_STRICT);
         if ($oldErrorHandler === NULL) {
             $errorHandlerSet = TRUE;
         } else {
             restore_error_handler();
         }
     }
     if (self::$xdebugLoaded === NULL) {
         self::$xdebugLoaded = extension_loaded('xdebug');
         self::$useXdebug = self::$xdebugLoaded;
     }
     $useXdebug = self::$useXdebug && $this->collectCodeCoverageInformation && !$test instanceof PHPUnit_Extensions_SeleniumTestCase && !$test instanceof PHPUnit_Framework_Warning;
     if ($useXdebug) {
         $this->codeCoverage->start($test);
     }
     PHPUnit_Util_Timer::start();
     try {
         $test->runBare();
     } catch (PHPUnit_Framework_AssertionFailedError $e) {
         $failure = TRUE;
     } catch (Exception $e) {
         $error = TRUE;
     }
     $time = PHPUnit_Util_Timer::stop();
     if ($useXdebug) {
         $data = $this->codeCoverage->stop(FALSE);
         if ($this->collectRawCodeCoverageInformation) {
             $this->rawCodeCoverageInformation[] = $data;
         } else {
             $filterGroups = array('DEFAULT', 'TESTS');
             if (!defined('PHPUNIT_TESTSUITE')) {
                 $filterGroups[] = 'PHPUNIT';
             }
             $this->codeCoverage->append($data, $test, $filterGroups);
         }
     }
     if ($errorHandlerSet === TRUE) {
         restore_error_handler();
     }
     $test->addToAssertionCount(PHPUnit_Framework_Assert::getCount());
     if ($error === TRUE) {
         $this->addError($test, $e, $time);
     } else {
         if ($failure === TRUE) {
             $this->addFailure($test, $e, $time);
         }
     }
     $this->endTest($test, $time);
 }
Exemple #14
0
 /**
  * @param float $timeElapsed
  */
 protected function printHeader($timeElapsed)
 {
     if (isset($_SERVER['REQUEST_TIME'])) {
         $timeElapsed = PHPUnit_Util_Timer::secondsToTimeString(time() - $_SERVER['REQUEST_TIME']);
     } else {
         $timeElapsed = PHPUnit_Util_Timer::secondsToTimeString($timeElapsed);
     }
     $this->write(sprintf("%sTime: %s\n\n", $this->verbose ? "\n" : "\n\n", $timeElapsed));
 }
 /**
  * 
  * Compares two API objects and notify the PHPUnit and kaltura listeners 
  * @param KalturaObjectBase $object1
  * @param KalturaObjectBase $object2
  */
 public static function CompareAPIObjects(KalturaObjectBase $outputReference, KalturaObjectBase $actualResult, $validErrorFields)
 {
     //Use reflection to compare the objects
     $outputReferenceReflector = new ReflectionClass($outputReference);
     $properties = $outputReferenceReflector->getProperties(ReflectionProperty::IS_PUBLIC);
     $newErrors = array();
     foreach ($properties as $property) {
         $propertyName = $property->getName();
         //Start the phpunit timer so we can gather performance data
         PHPUnit_Util_Timer::start();
         //If the field is in the valid failure list then we skip him
         if (in_array($propertyName, $validErrorFields)) {
             continue;
         } else {
             $expectedValue = $property->getValue($outputReference);
             $actualValue = $property->getValue($actualResult);
             $assertToPerform = "assertEquals";
             $this->compareOnField($propertyName, $actualValue, $expectedValue, $assertToPerform);
             //if this is an array we need to change it to a string
         }
     }
     return $newErrors;
 }