/** * Constructor * * If $pass is false, the global Tulip config property "PASS" will be set to false * * @param boolean $pass * @param string $text */ public function Tulip_Test($pass, $text) { if (!$pass) { Tulip::config("PASS", false); } $this->pass = $pass; $this->text = $text; }
function Tulip_Output_shutdown() { // Report fatal errors $fatal_errors = array(); preg_match_all('/fatal\\s+error.*?:(.*)/i', $tmp = ob_get_clean(), $fatal_errors); $fatal_errors = $fatal_errors[1]; if (count($fatal_errors)) { $last = end(end(Tulip::modules())->units()); foreach ($fatal_errors as &$fatal_error) { $last->add(false, preg_replace('/^\\s+|\\s+$|<.*?>/', "", $fatal_error), false); } } // Get the template $template = Tulip::config("TEMPLATE"); if (substr($template, 0, 1) == "#") { $template = dirname(__FILE__) . DIRECTORY_SEPARATOR . "Output" . DIRECTORY_SEPARATOR . substr($template, 1) . ".php"; } // If template does not exist, try to get it from path if (!file_exists($template)) { $file = false; $dirs = explode(PATH_SEPARATOR, Tulip::config("PATH")); foreach ($dirs as $dir) { if (file_exists($dir . DIRECTORY_SEPARATOR . $template)) { $file = $dir . DIRECTORY_SEPARATOR . $template; break; } } if (!$file) { echo "Tulip: couldn't find template file {$template}"; exit; } $template = $file; } // Include the template and render require_once $template; }
?> </li> <?php } ?> </ol> </strong> </li> <?php } } ?> </ol> <p id="tulip-result"> Tests completed in <?php echo number_format(microtime(true) - Tulip::config("START_TIME"), 2); ?> seconds. <br /> <span class="passed"><?php echo $pass; ?> </span> out of <span class="total"><?php echo $pass + $fail; ?> </span> tests passed, <span class="failed"><?php echo $fail; ?> </span> failed.
/** * Constructor * * @param mixed $module * @param array $labels * @return Tulip */ public function Tulip($moduleName = false, $labels = false) { // Manage params if ($labels === false) { if (is_array($moduleName)) { $labels = $moduleName; $moduleName = false; } } if ($moduleName === false) { if (property_exists($this, "module")) { $moduleName = $this->module; } } if (!is_string($moduleName)) { $moduleName = false; } if (!is_array($labels)) { $labels = array(); } if (property_exists($this, "labels") && is_array($this->labels)) { foreach ($this->labels as $name => $alias) { if (!isset($labels[$name])) { $labels[$name] = $alias; } } } // Get the page outputer require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "Tulip" . DIRECTORY_SEPARATOR . "Output.php"; // Get the class $class = new ReflectionClass(get_class($this)); // Get the module name $moduleName = ($moduleName ? $moduleName : $class->getName()) . " Module"; // Control if the module has to be executed if (Tulip::$config["QUERY_STRING"] && Tulip::incompatible($moduleName, Tulip::$config["QUERY_STRING"], true)) { return; } // Get the methods $tests = $class->getMethods(ReflectionMethod::IS_PUBLIC); // Init a module $module = new Tulip_Module($moduleName); // Stack the result Tulip::$modules[] = $module; // For each public method foreach ($tests as $test) { $name = $test->getName(); if (isset($labels[$name])) { $name = $labels[$name]; } if ($test->isStatic() || $test->isConstructor() || $test->getDeclaringClass()->getName() == "Tulip" || Tulip::$config["QUERY_STRING"] && Tulip::incompatible("{$moduleName}: {$name}", Tulip::$config["QUERY_STRING"])) { continue; } // Create a unit test repository and set it as current $this->current = new Tulip_Unit($name); // Add to the module $module->add($this->current); try { // Invoke the test $test->invokeArgs($this, array()); } catch (Exception $e) { // Eventually notify an error $this->current->add(false, $e->getMessage(), false); } // Control we have all expected tests (if needs be) $this->current->checkExpected(); // Forget about the current unset($this->current); } }