function _execute($file) { global $executable; $command = new LimeCommand($executable, dirname(__FILE__) . '/LimeAnnotationSupport/' . $file); $command->execute(); return $command; }
// which test suite should I run for reference? define('TEST_SCRIPT', dirname(__FILE__) . '/prove.php'); // roger! // the resulting number of test runs is PROCESSES_LIMIT*TEST_RUNS include dirname(__FILE__) . '/../../lib/LimeAutoloader.php'; LimeAutoloader::register(); $processCounts = array(); $stats = array(); for ($i = 1; $i <= PROCESSES_LIMIT; ++$i) { $stats[$i] = array(); for ($j = 1; $j <= TEST_RUNS; ++$j) { $processCounts[] = $i; } } shuffle($processCounts); foreach ($processCounts as $i => $processCount) { $time = microtime(true); echo "Running " . ($i + 1) . " of " . count($processCounts) . " ({$processCount} processes)\n"; $command = new LimeCommand(TEST_SCRIPT, array('processes' => $processCount)); $command->execute(); $stats[$processCount][] = microtime(true) - $time; } foreach ($stats as $key => $stat) { $stats[$key] = array_sum($stat) / count($stat); } echo "\n"; echo "BENCHMARK RESULTS\n"; echo "=================\n"; foreach ($stats as $nb => $stat) { echo str_pad("{$nb} processes", 20, ' ') . str_pad(round($stat, 2) . ' sec', 10, ' ') . round(-100 * ($stat - $stats[1]) / $stats[1], 2) . "%\n"; }
// assertions $t->ok($input->done(), 'The input is done'); // @Test: Additional lines and comments are ignored // fixtures $output->setExpectNothing(); $output->replay(); // test $input->parse("Some foobar text\n"); $input->parse("# Some comment\n"); // assertions $t->ok($input->done(), 'The input is done'); // @Test: A PHP error is passed to error() - invalid identifier // @Test: Case 1 - Invalid identifier // fixtures $output->error(new LimeError("syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '\$'", $file, 1, 'Parse error')); $output->replay(); file_put_contents($file, '<?php $1invalidname;'); $command = new LimeCommand($executable, $file); $command->execute(); // test $input->parse($command->getOutput()); // @Test: Case 2 - Failed require // fixtures $output->error(new LimeError("require(foobar.php): failed to open stream: No such file or directory", $file, 1, 'Warning')); $output->error(new LimeError("require(): Failed opening required 'foobar.php' (include_path='" . get_include_path() . "')", $file, 1, 'Fatal error')); $output->replay(); file_put_contents($file, '<?php require "foobar.php";'); $command = new LimeCommand($executable, $file); $command->execute(); // test $input->parse($command->getOutput());
/* * This file is part of the Lime framework. * * (c) Fabien Potencier <*****@*****.**> * (c) Bernhard Schussek <*****@*****.**> * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ LimeAnnotationSupport::enable(); $t = new LimeTest(); // @Before $executable = new LimeExecutable(LimeExecutable::php() . ' %file%'); // @Test: A PHP file can be executed // fixtures $file = tempnam(sys_get_temp_dir(), 'lime'); file_put_contents($file, <<<EOF <?php echo "Test"; file_put_contents("php://stderr", "Errors"); exit(1); EOF ); // test $command = new LimeCommand($executable, $file); $command->execute(); // assertions $t->is($command->getOutput(), 'Test', 'The output is correct'); $t->is($command->getErrors(), 'Errors', 'The errors are correct'); $t->is($command->getStatus(), 1, 'The return value is correct');