/** * Runs an empty test to determine the benchmark overhead and run each test once */ private function warmup() { $warmup = new SimpleTest('warmup', function () { }); $warmup->run(); foreach ($this->tests as $test) { $test->run(); } $this->base_results = $warmup->run($this->n); }
/** * Checks the current test context to see if a test has * ever been run. * @return boolean True if tests have run. */ function tests_have_run() { if ($context = SimpleTest::getContext()) { return (bool) $context->getTest(); } return false; }
function run($reporter) { $context = SimpleTest::getContext(); $context->setTest($this); $context->setReporter($reporter); $this->reporter = $reporter; $this->reporter->paintCaseStart($this->getLabel()); if ($this->needPDO) { $this->reporter->makeDry(!$this->assertTrue(class_exists('PDO', false), 'PDO does not exists ! You should install PDO because tests need it.')); } $this->setUpRun(); foreach ($this->getTests() as $method) { if ($this->reporter->shouldInvoke($this->getLabel(), $method)) { $this->skip(); if ($this->shouldSkip()) { break; } $invoker = $this->reporter->createInvoker($this->createInvoker()); $invoker->before($method); $invoker->invoke($method); $invoker->after($method); } } $this->tearDownRun(); $this->reporter->paintCaseEnd($this->getLabel()); unset($this->reporter); return $reporter->getStatus(); }
function AllTests() { $this->TestSuite('FlatDB tests - Simple test' . SimpleTest::getVersion()); $this->addFile(dirname(__FILE__) . '/test_rows.php'); $this->addFile(dirname(__FILE__) . '/test_columns.php'); $this->addFile(dirname(__FILE__) . '/test_read_add.php'); }
public static function setPreference() { if (TextReporter::inCli()) { SimpleTest::prefer(new Xml_Chris()); } else { SimpleTest::prefer(new Html_Chris()); } }
/** * @param string $testCase * @param string $method * @return boolean */ public function shouldInvoke($testCase, $method) { $test = SimpleTest::getContext()->getTest(); if ($test instanceof CakeTestCase && in_array(strtolower($method), $test->methods)) { return true; } return parent::shouldInvoke($testCase, $method); }
function AllTests() { $this->GroupTest('All tests for SimpleTest ' . SimpleTest::getVersion()); $this->addTestCase(new UnitTests()); $this->addTestFile(dirname(__FILE__) . '/shell_test.php'); $this->addTestFile(dirname(__FILE__) . '/live_test.php'); $this->addTestFile(dirname(__FILE__) . '/acceptance_test.php'); }
/** * Wires up the error queue for a single test. * * @return SimpleErrorQueue Queue connected to the test. */ public function &_createErrorQueue() { $context =& SimpleTest::getContext(); $test =& $this->getTestCase(); $queue =& $context->get('SimpleErrorQueue'); $queue->setTestCase($test); return $queue; }
/** * Wires up the error queue for a single test. * @return SimpleErrorQueue Queue connected to the test. * @access private */ protected function createErrorQueue() { $context = SimpleTest::getContext(); $test = $this->getTestCase(); $queue = $context->get('SimpleErrorQueue'); $queue->setTestCase($test); return $queue; }
function __construct() { parent::__construct('All tests for SimpleTest ' . SimpleTest::getVersion()); $this->addFile(dirname(__FILE__) . '/unit_tests.php'); $this->addFile(dirname(__FILE__) . '/shell_test.php'); $this->addFile(dirname(__FILE__) . '/live_test.php'); $this->addFile(dirname(__FILE__) . '/acceptance_test.php'); }
function &_getRegistry() { static $registry = false; if (!$registry) { $registry = SimpleTest::_getDefaults(); } return $registry; }
/** * @param string $testName */ protected function shouldPaintMethod($testName) { $testCase = SimpleTest::getContext()->getTest(); if (!$testCase instanceof CakeTestCase) { return true; } return !in_array(strtolower($testName), $testCase->methods); }
public function AllTests() { $this->TestSuite('All tests for SimpleTest ' . SimpleTest::getVersion()); $this->addFile(dirname(__FILE__) . '/unit_tests.php'); $this->addFile(dirname(__FILE__) . '/shell_test.php'); $this->addFile(dirname(__FILE__) . '/live_test.php'); $this->addFile(dirname(__FILE__) . '/acceptance_test.php'); }
/** * Starts with a fresh browser with no * cookie or any other state information. The * exception is that a default proxy will be * set up if specified in the options. * @access public */ function __construct() { $this->user_agent = $this->createUserAgent(); $this->user_agent->useProxy(SimpleTest::getDefaultProxy(), SimpleTest::getDefaultProxyUsername(), SimpleTest::getDefaultProxyPassword()); $this->page = new SimplePage(); $this->history = $this->createHistory(); $this->ignore_frames = false; $this->maximum_nested_frames = DEFAULT_MAX_NESTED_FRAMES; }
public function ExtensionsTests() { $this->TestSuite('Extension tests for SimpleTest ' . SimpleTest::getVersion()); $nodes = new RecursiveDirectoryIterator(dirname(__FILE__) . '/../extensions/'); foreach (new RecursiveIteratorIterator($nodes) as $node) { if (preg_match('/test\\.php$/', $node->getFilename())) { $this->addFile($node->getPathname()); } } }
public function __construct() { parent::__construct('All tests for SimpleTest ' . SimpleTest::getVersion()); $this->addFile(dirname(__FILE__) . '/unit_tests.php'); $this->addFile(dirname(__FILE__) . '/shell_test.php'); $this->addFile(dirname(__FILE__) . '/live_test.php'); // jakoch: disabled acceptance tests. // because, we will not test against a live server over the network. //$this->addFile(dirname(__FILE__) . '/acceptance_test.php'); }
/** * Assembles the appopriate reporter for the environment. */ function DefaultReporter() { if (SimpleReporter::inCli()) { global $argv; $parser = new SimpleCommandLineParser($argv); $interfaces = $parser->isXml() ? array('XmlReporter') : array('TextReporter'); $reporter =& new SelectiveReporter(SimpleTest::preferred($interfaces), $parser->getTestCase(), $parser->getTest()); } else { $reporter =& new SelectiveReporter(SimpleTest::preferred('HtmlReporter'), @$_GET['c'], @$_GET['t']); } $this->SimpleReporterDecorator($reporter); }
public function __construct() { parent::__construct('All tests for SimpleTest ' . SimpleTest::getVersion()); $this->addFile(dirname(__FILE__) . '/unit_tests.php'); $this->addFile(dirname(__FILE__) . '/shell_test.php'); $this->addFile(dirname(__FILE__) . '/live_test.php'); // The acceptance tests "examples" are served via PHP's built-in webserver, // which is available from PHP5.4 on. if (version_compare(PHP_VERSION, '5.4.0', '>=')) { $this->addFile(dirname(__FILE__) . '/acceptance_test.php'); } }
function __construct() { /* And a little hack to make sure PHP does not timeout */ // http://www.php.net/manual/en/info.configuration.php#ini.max-execution-time set_time_limit(max(5 * 60, ini_get('max_execution_time'))); parent::__construct('All tests for SimpleTest ' . SimpleTest::getVersion()); $this->addFile(dirname(__FILE__) . '/unit_tests.php'); $this->addFile(dirname(__FILE__) . '/shell_test.php'); $this->addFile(dirname(__FILE__) . '/live_test.php'); $this->addFile(dirname(__FILE__) . '/acceptance_test.php'); }
function AllTests() { $this->TestSuite('All tests for evalcomix_tool ' . SimpleTest::getVersion()); $this->addFile(dirname(__FILE__) . '/testevalcomix_tool.php'); $this->addFile(dirname(__FILE__) . '/testevalcomix.php'); $this->addFile(dirname(__FILE__) . '/testevalcomix_assessments.php'); $this->addFile(dirname(__FILE__) . '/testevalcomix_modes.php'); $this->addFile(dirname(__FILE__) . '/testevalcomix_modes_extra.php'); $this->addFile(dirname(__FILE__) . '/testevalcomix_modes_time.php'); $this->addFile(dirname(__FILE__) . '/testevalcomix_tasks.php'); //$this->addFile(dirname(__FILE__) . '/testwebservice_evalcomix_client.php'); $this->addFile(dirname(__FILE__) . '/testcalculator_average.php'); }
public function __construct() { parent::__construct('All tests for SimpleTest ' . SimpleTest::getVersion()); $this->addFile(__DIR__ . '/unit_tests.php'); $this->addFile(__DIR__ . '/shell_test.php'); /** * The "live" and "acceptance" tests require a running local webserver on "localhost:8080". * We are using PHP's built-in webserver to serve the "test/site". * The start command for the server is: `php -S localhost:8080 -t test/site`. */ $this->addFile(__DIR__ . '/live_test.php'); $this->addFile(__DIR__ . '/acceptance_test.php'); }
/** * Invokes a test method and dispatches any * untrapped errors. Called back from * the visiting runner. * @param string $method Test method to call. * @access public */ function invoke($method) { $context =& SimpleTest::getContext(); $queue =& $context->get('SimpleErrorQueue'); $queue->setTestCase($this->GetTestCase()); set_error_handler('SimpleTestErrorHandler'); parent::invoke($method); while (list($severity, $message, $file, $line) = $queue->extract()) { $severity = SimpleErrorQueue::getSeverityAsString($severity); $test =& $this->getTestCase(); $test->error($severity, $message, $file, $line); } restore_error_handler(); }
/** * Lists rather then invokes a test method. Consequently, * we do not invoke the setUp() and tearDown() calls either. * @param string $method Test method to call. * @access public */ function invoke($method) { $context = SimpleTest::getContext(); $test = $this->getTestCase(); // $context->getTest(); $reporter = $context->getReporter(); // use 'user signal' as the way to render the list entry: $case = get_class($test); if ($case != $test->getLabel()) { $case = sprintf("%s [%s]", $case, $test->getLabel()); } $show_breadcrumb = $reporter->includeBreadCrumb(false); $reporter->paintSignal("Test", sprintf("Case: %s | Method: %s", $case, $method)); $reporter->includeBreadCrumb($show_breadcrumb); }
/** * Invokes a test method whilst trapping expected * exceptions. Any left over unthrown exceptions * are then reported as failures. * @param string $method Test method to call. */ function invoke($method) { $trap = SimpleTest::getContext()->get('SimpleExceptionTrap'); $trap->clear(); try { parent::invoke($method); } catch (Exception $exception) { if (!$trap->isExpected($this->getTestCase(), $exception)) { $this->getTestCase()->exception($exception); } $trap->clear(); } if ($message = $trap->getOutstanding()) { $this->getTestCase()->fail($message); } }
protected function Form_Create() { $filesToSkip = array("QUnitTestCaseBase.php", "QTestForm.tpl.php"); $arrFiles = QFolder::listFilesInFolder(__QCUBED_CORE__ . '/tests/qcubed-unit/'); $arrTests = array(); foreach ($arrFiles as $filename) { if (!in_array($filename, $filesToSkip)) { require_once __QCUBED_CORE__ . '/tests/qcubed-unit/' . $filename; $arrTests[] = str_replace(".php", "", $filename); } } $suite = new TestSuite('QCubed ' . QCUBED_VERSION_NUMBER_ONLY . ' Unit Tests - SimpleTest ' . SimpleTest::getVersion()); foreach ($arrTests as $className) { $suite->add(new $className($this)); } $suite->run(new QHtmlReporter()); }
public function send($v1, $v2) { // test for context $context = SimpleTest::getContext(); $test = $context->getTest(); $mock = $this->mock; foreach ($this->_expected_context as $key => $value) { $test->assertEqual($value, $this->_context->get($key)); } $step = $mock->getCallCount('send'); if (isset($this->_expected_context_at[$step])) { foreach ($this->_expected_context_at[$step] as $key => $value) { $test->assertEqual($value, $this->_context->get($key)); } } // boilerplate mock code, does not have return value or references $args = func_get_args(); $mock->invoke('send', $args); }
function AllTests() { set_time_limit(500); $this->TestSuite('All PHP MySpace Test ' . SimpleTest::getVersion()); $this->addFile(dirname(__FILE__) . '\\CurrentUserIdTest.php'); $this->addFile(dirname(__FILE__) . '\\AlbumTest.php'); $this->addFile(dirname(__FILE__) . '\\MediaItemTest.php'); $this->addFile(dirname(__FILE__) . '\\MediaItemCommentsTest.php'); $this->addFile(dirname(__FILE__) . '\\ActivitiesTest.php'); $this->addFile(dirname(__FILE__) . '\\AppDataTest.php'); $this->addFile(dirname(__FILE__) . '\\GroupTest.php'); $this->addFile(dirname(__FILE__) . '\\PeopleTest.php'); $this->addFile(dirname(__FILE__) . '\\NotificationTest.php'); $this->addFile(dirname(__FILE__) . '\\StatusMoodTest.php'); $this->addFile(dirname(__FILE__) . '\\ProfileCommentsTest.php'); $this->addFile(dirname(__FILE__) . '\\OpenSearchTest.php'); $this->addFile(dirname(__FILE__) . '\\PortableContactsTest.php'); $this->addFile(dirname(__FILE__) . '\\SubscriptionTest.php'); }
function run(&$reporter) { SimpleTest::setCurrent($this); $this->_reporter =& $reporter; $this->_reporter->paintCaseStart($this->getLabel()); if ($this->needPDO) { $this->_reporter->makeDry(!$this->assertTrue(class_exists('PDO', false), 'PDO does not exists ! You should install PDO because tests need it.')); } foreach ($this->getTests() as $method) { if ($this->_reporter->shouldInvoke($this->getLabel(), $method)) { $invoker =& $this->_reporter->createInvoker($this->createInvoker()); $invoker->before($method); $invoker->invoke($method); $invoker->after($method); } } $this->_reporter->paintCaseEnd($this->getLabel()); unset($this->_reporter); return $reporter->getStatus(); }
public static function call_simpletest(pakeTask $task, $type = 'text', $dirs = array()) { if (!class_exists('TestSuite')) { throw new pakeException('You must install SimpleTest to use this task.'); } SimpleTest::ignore('UnitTestCase'); $base_test_dir = 'test'; $test_dirs = array(); // run tests only in these subdirectories if ($dirs) { foreach ($dirs as $dir) { $test_dirs[] = $base_test_dir . DIRECTORY_SEPARATOR . $dir; } } else { $test_dirs[] = $base_test_dir; } $files = pakeFinder::type('file')->name('*Test.php')->in($test_dirs); if (count($files) == 0) { throw new pakeException('No test to run.'); } $test = new TestSuite('Test suite in (' . implode(', ', $test_dirs) . ')'); foreach ($files as $file) { $test->addFile($file); } ob_start(); if ($type == 'html') { $result = $test->run(new HtmlReporter()); } else { if ($type == 'xml') { $result = $test->run(new XmlReporter()); } else { $result = $test->run(new TextReporter()); } } $content = ob_get_contents(); ob_end_clean(); if ($task->is_verbose()) { echo $content; } }
/** * Invokes a test method whilst trapping expected * exceptions. Any left over unthrown exceptions * are then reported as failures. * * @param string $method Test method to call. */ public function invoke($method) { $trap = SimpleTest::getContext()->get('SimpleExceptionTrap'); $trap->clear(); try { $has_thrown = false; parent::invoke($method); } catch (Exception $exception) { $has_thrown = true; if (!$trap->isExpected($this->getTestCase(), $exception)) { $this->getTestCase()->exception($exception); } $trap->clear(); } if ($message = $trap->getOutstanding()) { $this->getTestCase()->fail($message); } if ($has_thrown) { try { parent::getTestCase()->tearDown(); } catch (Exception $e) { } } }