public function __construct($class_, Test_Unit_Runner $runner_ = null) { $this->m_runner = $runner_; $this->m_class = new \ReflectionClass($class_); $rootPath = realpath($runner_->getTestRootPath()); $testClassPath = realpath($this->m_class->getFileName()); $this->m_path = str_replace("{$rootPath}/", '', $testClassPath); $annotations = Annotations::get($class_); foreach ($this->m_class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { if ($ignoreAnnotation = $annotations->getMethodAnnotation($method->name, Annotation_Ignore::NAME)) { if (null !== $ignoreAnnotation->value && false === @method_exists($this->m_class->name, $ignoreAnnotation->value)) { throw new Exception_IllegalArgument('test/unit/internal/dynamicproxy', sprintf('Illegal argument in @%1$s(value=%4$s) %2$s::%3$s().', Annotation_Ignore::NAME, $this->m_class->name, $method->name, $ignoreAnnotation->value)); } else { if (null !== $ignoreAnnotation->value) { if (false !== ($reason = call_user_func([$this->m_class->name, $ignoreAnnotation->value]))) { if (is_string($reason)) { $this->m_skippedTestsReasons[$method->name] = $reason; } $this->m_skippedTests[$method->name] = true; } } else { $this->m_skippedTests[$method->name] = true; } } } if ($testAnnotation = $annotations->getMethodAnnotation($method->name, Annotation_Test::NAME)) { array_push($this->m_tests, $method); $expectedFail = $testAnnotation->expectedFail; $expectedException = $testAnnotation->expectedException; if (null !== $expectedException && false === @class_exists($expectedException)) { throw new Exception_IllegalArgument('test/unit/internal/dynamicproxy', sprintf('Illegal argument in @%1$s(expectedException=%4$s) %2$s::%3$s().', Annotation_Test::NAME, $this->m_class->name, $method->name, $expectedException)); } if (null !== $expectedException) { $this->m_exceptionsExpected[$method->name] = $expectedException; } if (null != $expectedFail && 'false' !== trim(strtolower($expectedFail))) { $this->m_failedExpected[$method->name] = true; } } /* * Search for Before-/AfterMethod/-Class/-Suite annotations * Only the first occurence per method will be respected. */ foreach (self::$m_staticAnnotations as $staticAnnotation) { if ($annotations->hasMethodAnnotation($method->name, $staticAnnotation)) { $this->m_mappedMethods[$staticAnnotation] = $method->name; break; } } $this->m_methods[$method->name] = $method; if ($profileAnnotation = $annotations->getMethodAnnotation($method->name, Annotation_Profile::NAME)) { $this->m_profileMethods[$method->name] = null; if (Annotation_Profile::VALUE_FORK == $profileAnnotation->value) { $this->m_profileMethodsForked[$method->name] = null; } } } }
public function run() { if (false === $this->isAttached()) { $this->attach(new Io_Pipe_Stdin(), new Io_Pipe_Stdout(), new Io_Pipe_Stderr()); } $this->open(); $mandatoryDefined = $this->hasArgument('path') && $this->hasArgument('build'); if ($this->hasArgument('help') || $this->hasArgument('version') || !$mandatoryDefined) { if ($this->hasArgument('help') || !$mandatoryDefined) { $this->appendOptions(); } else { $this->appendInfo(); } $this->flush(); $this->close(); return; } Cache::disable(); $test = Test_Unit_Runner::create(); $test->output = new Test_Output_Console($this); if ($this->hasArgument('config')) { $test->configuration = $this->getArgument('config'); } if ($this->hasArgument('path')) { $test->setTestRootPath($this->getArgument('path')); } if ($this->hasArgument('build')) { $test->setBuildPath($this->getArgument('build')); } if ($this->hasArgument('analyzers')) { $analyzers = explode(',', strtolower($this->getArgument('analyzers'))); if (in_array('emma', $analyzers)) { $test->addListener(new \Components\Test_Listener_Emma($test->getTestRootPath())); } } $test->run(); $this->close(); Cache::enable(); }