public static function run($className) { $runner = new TestRunner(); $rc = new ReflectionClass($className); $methods = $rc->GetMethods(ReflectionMethod::IS_PUBLIC); foreach ($methods as $m) { $name = $m->name; if (!$runner->isValidTest($name)) { continue; } $count = count($className::$errors); $rt = new $className(); try { $rt->setUp(); $rt->{$name}(); echo $count === count($className::$errors) ? "." : "F"; } catch (Exception $e) { if ($e instanceof RedisException) { $className::$errors[] = "Uncaught exception '" . $e->getMessage() . "' ({$name})\n"; echo 'F'; } else { echo 'S'; } } } echo "\n"; echo implode('', $className::$warnings); if (empty($className::$errors)) { echo "All tests passed.\n"; return 0; } echo implode('', $className::$errors); return 1; }
public function runner($reg = NULL) { $runner = new TestRunner(); if (!empty($reg)) { $runner->useRegistry($reg); } return $runner; }
static function &get($directory = null, $writer = 'TextualWriter') { static $instance; if (!isset($instance)) { $instance = new TestRunner($directory); $instance->set_writer(new $writer()); } return $instance; }
public function testPhpRQ() { if (!self::$redis instanceof Client) { throw new \Exception('The PhpRQ test suit can be run only with php-rq-run-tests binary or by implementing the ClientProvider and running the TestRunner in your test suite.'); } $redisProvider = new ClientProvider(); $redisProvider->registerProvider(function () { self::$redis->flushdb(); self::$redis->script('flush'); return self::$redis; }); $test = new TestRunner($redisProvider); $test->run(); }
public function failedTestTeardown() { $this->console(CONSOLE_LINE); $this->console("Terminating iPhone application..."); $this->teardown(); return parent::failedTestTeardown(); }
/** * Override the default reporter with a custom configured subclass. * * @param string $reporter */ static function set_reporter($reporter) { if (is_string($reporter)) { $reporter = new $reporter(); } self::$default_reporter = $reporter; }
function parse_options() { $options = getopt("h", array("clients-count:", "log-junit", "verbose", "build")); if (isset($options['h'])) { print_info(); die; } if (isset($options['build'])) { $options['verbose'] = true; $options['log-junit'] = true; } if (isset($options['clients-count'])) { define('SELENIUM_CLIENTS_COUNT', $options['clients-count']); } if (isset($options['log-junit'])) { TestRunner::$log_xml = true; shell_exec("rm /tmp/TEST*.xml"); } if (isset($options['verbose'])) { TestRunner::$verbose = true; } if (!defined('SELENIUM_CLIENTS_COUNT')) { define('SELENIUM_CLIENTS_COUNT', 5); } $runner = new testRunner(); $runner->start(SELENIUM_CLIENTS_COUNT); }
function init() { parent::init(); if (!Permission::check('ADMIN')) { return Security::permissionFailure(); } TestRunner::use_test_manifest(); }
/** * @return Array */ public static function get_all_tests() { require_once 'sapphire/tests/bootstrap.php'; TestRunner::use_test_manifest(); $tests = ClassInfo::subclassesFor('SapphireTest'); array_shift($tests); return $tests; }
/** * Loads kernel file. * * @param ContainerBuilder $container */ public function process(ContainerBuilder $container) { // Connect to database and build manifest $frameworkPath = $container->getParameter('behat.silverstripe_extension.framework_path'); $_GET['flush'] = 1; require_once $frameworkPath . '/core/Core.php'; \TestRunner::use_test_manifest(); unset($_GET['flush']); // Remove the error handler so that PHPUnit can add its own restore_error_handler(); }
public function testIsTestFile() { $this->guy->createTestFolderTree($this->tmpPath1); $this->assertTrue($this->guy->isTestFolderTree($this->tmpPath1)); // real tests $this->assertTrue(TestRunner::isTestFile($this->tmpPath1 . DS . 'subFolder1' . DS . 'unit' . DS . 'funTest.php')); $this->assertTrue(TestRunner::isTestFile($this->tmpPath1 . DS . 'subFolder2' . DS . 'unit' . DS . 'boringTestCest.php')); $this->assertTrue(TestRunner::isTestFile($this->tmpPath1 . DS . 'subFolder2' . DS . 'unit' . DS . 'interestingTestCept.php')); // not real tests $this->assertFalse(TestRunner::isTestFile($this->tmpPath1 . DS . 'README.txt')); $this->assertFalse(TestRunner::isTestFile($this->tmpPath1 . DS . 'nonExistentFile.txt')); }
/** * Overwrites beforeRunTests. Initiates coverage-report generation if * $coverage has been set to true (@see setCoverageStatus). */ protected function beforeRunTests() { if ($this->getCoverageStatus()) { // blacklist selected folders from coverage report $modules = $this->moduleDirectories(); foreach (TestRunner::config()->coverage_filter_dirs as $dir) { if ($dir[0] == '*') { $dir = substr($dir, 1); foreach ($modules as $module) { PHPUnit_Util_Filter::addDirectoryToFilter(BASE_PATH . '/' . $dir); } } else { PHPUnit_Util_Filter::addDirectoryToFilter(BASE_PATH . '/' . $dir); } } $this->getFrameworkTestResults()->collectCodeCoverageInformation(true); } }
/** * Overwrites beforeRunTests. Initiates coverage-report generation if * $coverage has been set to true (@see setCoverageStatus). */ protected function beforeRunTests() { if ($this->getCoverageStatus()) { $this->coverage = new PHP_CodeCoverage(); $coverage = $this->coverage; $filter = $coverage->filter(); $modules = $this->moduleDirectories(); foreach (TestRunner::config()->coverage_filter_dirs as $dir) { if ($dir[0] == '*') { $dir = substr($dir, 1); foreach ($modules as $module) { $filter->addDirectoryToBlacklist(BASE_PATH . "/{$module}/{$dir}"); } } else { $filter->addDirectoryToBlacklist(BASE_PATH . '/' . $dir); } } $filter->addFileToBlacklist(__FILE__, 'PHPUNIT'); $coverage->start(self::get_test_name()); } }
php RunTests.php [options] [file or directory] Options: -p <php> Specify PHP-CGI executable to run. -c <path> Look for php.ini in directory <path> or use <path> as php.ini. -d key=val Define INI entry 'key' with value 'val'. -l <path> Specify path to shared library files (LD_LIBRARY_PATH) -s Show information about skipped tests <?php } /** * Execute tests */ try { @unlink(__DIR__ . '/coverage.dat'); // @ - file may not exist $manager = new TestRunner; $manager->parseArguments(); $res = $manager->run(); die($res ? 0 : 1); } catch (Exception $e) { echo 'Error: ', $e->getMessage(), "\n"; die(2); }
public function run($app) { $this->app = $app; if (empty($app) || !is_file($app)) { return FAILURE; } parent::run(); }
function tests($request) { return TestRunner::create(); }
$this->fail($e->getMessage()); } } private function validateArgv() { try { $argvLen = count($this->argv); foreach (range(1, $argvLen - 1) as $argvIndex) { if (preg_match('/\\.php$/', $this->argv[$argvIndex])) { $this->testFile = $this->argv[$argvIndex]; } } if ($this->testFile == null) { throw new \Exception('Missing argument: test file'); } // if($argvLen > 2) { // throw new \Exception('Too many arguments'); // } } catch (\Exception $e) { $this->fail($e->getMessage()); } } } // $stop = getopt('', ['stop-on-fail:']); // var_dump($stop); // die(); // var_dump($argv); // //var_dump($argc); // die(); $testRunner = new TestRunner($argv); $testRunner->run();
/** * The master test class that performs the various upgrades of the system, * and calls private methods to test various sections of the upgrade. */ function testUpgrade() { $aConf = $GLOBALS['_MAX']['CONF']; // Run the tests for every set of preferences that have been defined foreach (array_keys($this->aPrefsOld) as $set) { if ($set == 1 && $aConf['database']['type'] != 'mysql') { // OpenX 2.4.4 is only valid for MySQL continue; } // Initialise the database at schema 542 $this->initDatabase(542, array('agency', 'affiliates', 'application_variable', 'audit', 'channel', 'clients', 'preference', 'preference_advertiser', 'preference_publisher', 'acls', 'acls_channel', 'banners', 'campaigns', 'tracker_append', 'trackers', 'userlog', 'variables', 'zones')); // Set up the database with the standard set of accounts, // preferences and settings $this->_setupAccounts(); $this->_setupPreferences($set); // Perform the required upgrade on the database $this->upgradeToVersion(543); $this->upgradeToVersion(544); $this->upgradeToVersion(546); // Test the results of the upgrade $this->_testMigratePrefsToSettings($set); $this->_testMigratePrefsToAppVars($set); $this->_testMigratePrefsToPrefs($set); $this->_testMigrateUsers($set); // Restore the testing environment TestRunner::setupEnv(null); $this->oDbh =& OA_DB::singleton(); } }
<?php ini_set("display_errors", 1); ini_set("error_reporting", E_ALL); require_once dirname(__FILE__).DIRECTORY_SEPARATOR."config.php"; require_once "PHPUnit/Autoload.php"; require_once "class/TestRunner.php"; $includeCoverage = false; if(isset($_GET["coverage"])) { $includeCoverage = true; } $runner = new TestRunner(false); if(isset($testSuite)) { foreach($testSuite as $onePath) { $runner->readFolder($onePath); } } if(isset($codeCoverageIgnoreDirectoryList)) { foreach($codeCoverageIgnoreDirectoryList as $oneDirectory) { $runner->codeCoverageIgnoreDirectory($oneDirectory); } }
public function Run(TestSuite &$suite, $filename = null, $extension = 'xml') { return parent::Run($suite, $filename, $extension); }
} } } // check results $this->check($test, $test->expect, $result); } catch (JsonLdException $e) { echo $eol . $e; $this->failed += 1; echo "FAIL{$eol}"; } } if (property_exists($manifest, 'name')) { $this->ungroup(); } } } } // get command line options $options = getopt('d:'); if ($options === false || !array_key_exists('d', $options)) { $var = 'path to json-ld.org/test-suite/tests'; echo "Usage: php jsonld-tests.php -d <{$var}>{$eol}"; exit(0); } // load and run tests $tr = new TestRunner(); $tr->group('JSON-LD'); $tr->run($tr->load($options['d'])); $tr->ungroup(); echo "Done. Total:{$tr->total} Passed:{$tr->passed} Failed:{$tr->failed}{$eol}"; /* end of file, omit ?> */
return "Hello, " . $name; } } class GreeterTest { private $testObj; public function setUp() { $this->testObj = new Greeter(); } public function testGreetUsesNameInHelloMessage() { $name = "Justin"; $expected = "Hello, " . $name; $actual = $this->testObj->greet($name); Test::assertEqual($expected, $actual); } public function testGreetAddsWorldWhenNameIsNotSpecified() { $expected = "Hello, World"; $actual = $this->testObj->greet(""); Test::assertEqual($expected, $actual); } public function tearDown() { unset($this->testObj); } } TestRunner::addTestClass("GreeterTest"); TestRunner::runAll();
$output = array(); } // run all test suites in each test folder $passedAllTests = true; foreach ($testFolders as $key => $folder) { // take a snapshot of all log files $snapshots = []; if (!empty(TestConfig::getConfig('testLogFiles'))) { foreach (explode(",", TestConfig::getConfig('testLogFiles')) as $k => $logFile) { $snapshots[$logFile] = FileSystemTools::tail($logFile, 30); } } // run the test echo 'RUN TESTS ' . $folder; ob_start(); $testResult = TestRunner::runTests($folder); $testOutput = ob_get_contents(); ob_end_clean(); if (!$testResult['result']) { $passedAllTests = false; $output[] = "TEST FAILED"; } else { $output[] = "TEST PASSED"; } $output[] = $testOutput; //$output=array_merge($output,$testResult['output']); // CHECK PHP LOG FILE if (!empty(TestConfig::getConfig('testLogFiles'))) { foreach (explode(",", TestConfig::getConfig('testLogFiles')) as $k => $logFile) { $lines = FileSystemTools::checkChangesToFile($snapshots[$logFile], $logFile); if (count($lines) > 0) {
$this->Mail->AddAddress(get("mail_to")); $this->assert($this->Mail->Send(), "Send failed"); } } /** * Create and run test instance. */ if (isset($HTTP_GET_VARS)) { $global_vars = $HTTP_GET_VARS; } else { $global_vars = $_REQUEST; } if (isset($global_vars["submitted"])) { echo "Test results:<br>"; $suite = new TestSuite("phpmailerTest"); $testRunner = new TestRunner(); $testRunner->run($suite); echo "<hr noshade/>"; } function get($sName) { global $global_vars; if (isset($global_vars[$sName])) { return $global_vars[$sName]; } else { return ""; } } ?> <html>
static function findTestFolders($paths) { $suites = array(); foreach (explode("::::", $paths) as $path) { if (is_dir($path)) { if (TestRunner::isTestSuiteFolder($path)) { $stagingSuiteName = str_replace(':', '_', str_replace(DS, '_', $path)); $suites[$stagingSuiteName] = $path; } $objects = scandir($path); if (sizeof($objects) > 0) { foreach ($objects as $file) { if ($file == "." || $file == "..") { continue; } if (is_dir($path . DS . basename($file))) { if (TestRunner::isTestSuiteFolder($path . DS . basename($file))) { $stagingSuiteName = str_replace(':', '_', str_replace(DS, '_', $path . DS . basename($file))); // ensure absolute file references $suites[$stagingSuiteName] = $path . DS . basename($file); } // recurse into folder $suites = array_merge($suites, TestRunner::findTestFolders($path . DS . basename($file))); } } } } } return $suites; }
function __construct() { parent::TestRunner(dirname(__FILE__) . '/'); }
} return false; } protected function getMedian($values) { sort($values); if (count($values) % 2 == 0) { // even, take an average of the middle two $top = count($values) / 2; $bottom = $top - 1; $median = bcdiv($values[$bottom] + $values[$top], 2, 6); } else { $idx = floor(count($values) / 2); $median = $values[$idx]; } return $median; } } $classes = array(); foreach (glob("profiles/*.php") as $filename) { include_once $filename; } foreach (get_declared_classes() as $strClass) { $class = new ReflectionClass($strClass); if ($class->implementsInterface('IProfile')) { $classes[] = $strClass; } } $tr = new TestRunner(); $tr->setClasses($classes); $tr->run();
if ($rmethod->isPublic() && preg_match("/^test_/", $rmethod->getName())) { try { $tests++; $rmethod->invoke($test); } catch (AssertionError $aerr) { $failures++; echo "--> [" . $rclass->getName() . "::" . $rmethod->getName() . "] " . $aerr->getMessage() . "\n"; } } } } catch (Exception $ex) { $errors++; } echo sprintf("[%s/%d] assertions: %d, failures: %d, errors: %d\n", $rclass->getName(), $tests, $test->assertions(), $failures, $errors); } } class FooTest extends UnitTest { public function test_one() { $this->assert(false); $this->assert(true); } public function test_two() { $this->assert(true); $this->assert(true); } } TestRunner::run(new FooTest());
} foreach ($args as $arg) { if (strpos($arg, '=') == false) { $_GET['args'][] = $arg; } else { $newItems = array(); parse_str(substr($arg, 0, 2) == '--' ? substr($arg, 2) : $arg, $newItems); $_GET = array_merge($_GET, $newItems); } } $_REQUEST = array_merge($_REQUEST, $_GET); } // Connect to database require_once $frameworkPath . '/core/Core.php'; require_once $frameworkPath . '/tests/FakeController.php'; global $databaseConfig; DB::connect($databaseConfig); // Now set a fake REQUEST_URI $_SERVER['REQUEST_URI'] = BASE_URL . '/dev'; // Fake a session $_SESSION = null; // Prepare manifest autoloader $controller = new FakeController(); // Get test manifest TestRunner::use_test_manifest(); SapphireTest::set_is_running_test(true); // Remove the error handler so that PHPUnit can add its own restore_error_handler(); if (!isset($_GET['flush']) || !$_GET['flush']) { Debug::message("WARNING: Manifest not flushed. " . "Add flush=1 as an argument to discover new classes or files.\n", false); }
<?php require_once 'TestRunner.php'; $runner = new TestRunner('all'); $runner->init(); $runner->requireDatabase(); $testDirs = array('/tests/core', '/plugins'); if ($runner->isBrowserPresent()) { $testDirs[] = '/tests/integration'; } else { $runner->appendIntro("<p>" . $runner->getNoBrowserErrorMessage() . "<br/>Skipping integration tests...</p>"); } $runner->setTestDirectories($testDirs); $runner->run(); /* assertTrue($x) Fail if $x is false assertFalse($x) Fail if $x is true assertNull($x) Fail if $x is set assertNotNull($x) Fail if $x not set assertIsA($x, $t) Fail if $x is not the class or type $t assertNotA($x, $t) Fail if $x is of the class or type $t assertEqual($x, $y) Fail if $x == $y is false assertNotEqual($x, $y) Fail if $x == $y is true assertWithinMargin($x, $y, $m) Fail if abs($x - $y) < $m is false assertOutsideMargin($x, $y, $m) Fail if abs($x - $y) < $m is true assertIdentical($x, $y) Fail if $x == $y is false or a type mismatch assertNotIdentical($x, $y) Fail if $x == $y is true and types match assertReference($x, $y) Fail unless $x and $y are the same variable assertClone($x, $y) Fail unless $x and $y are identical copies assertPattern($p, $x) Fail unless the regex $p matches $x assertNoPattern($p, $x) Fail if the regex $p matches $x