/** * @return Test[] */ public function getTests() { $class = new \ReflectionClass($this->suite); $methods = $class->getMethods(); $filtered = array_filter($methods, function (\ReflectionMethod $method) { return $this->filter->acceptsMethod($method) && $method->getDeclaringClass()->getName() == $this->suite && substr($method->getName(), 0, 1) != '_' && $method->getName() != PlainTestCase::BEFORE_METHOD && $method->getName() != PlainTestCase::AFTER_METHOD && !$method->isConstructor() && !$method->isStatic() && $method->isPublic(); }); foreach ($filtered as $method) { (yield $this->createTestCase($class, $method)); } }
/** * @return TestFilter */ public function getFilter() { $filter = new TestFilter(); if ($filterConfig = $this->get('filter', '/Spec$/')) { if (is_string($filterConfig)) { $filterConfig = ['class' => $filterConfig]; } if ($classFilter = $this->getIn($filterConfig, 'class')) { if (is_string($classFilter)) { $classFilter = ['name' => $classFilter]; } if ($name = $this->getIn($classFilter, 'name')) { $filter->filterClass(function (\ReflectionClass $class) use($name) { return preg_match($name, $class->getShortName()); }); } if ($subclass = $this->getIn($classFilter, 'subclass')) { $filter->filterClass(function (\ReflectionClass $class) use($subclass) { return $class->isSubclassOf($subclass); }); } } if ($fileFilter = $this->getIn($filterConfig, 'file')) { $filter->filterFile(function ($path) use($fileFilter) { return preg_match($fileFilter, $path); }); } if ($methodFilter = $this->getIn($filterConfig, 'method')) { if (is_string($methodFilter)) { $methodFilter = ['name' => $methodFilter]; } if ($name = $this->getIn($methodFilter, 'name')) { $filter->filterMethod(function (\ReflectionMethod $method) use($name) { return preg_match($name, $method->getName()); }); } if ($annotation = $this->getIn($methodFilter, 'annotation')) { $filter->filterMethod(function (\ReflectionMethod $method) use($annotation) { return preg_match($annotation, $method->getDocComment()); }); } } } return $filter; }
private function thenTheFilterShouldNotAcceptTheClass($class) { $this->assert->not()->isTrue($this->filter->acceptsClass(new \ReflectionClass($class))); }
private function isAcceptable(\ReflectionClass $class, $path) { return $class->getFileName() == $path && !$class->isAbstract() && $this->filter->acceptsFile($path) && $this->filter->acceptsClass($class); }