/** * 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); } }