Beispiel #1
0
 public function testNoClassIsFoundInANonPHPFIle()
 {
     $classes = ClassDiscoverer::getDeclaredClasses(__DIR__ . '/fixtures/notAPHPFile.html');
     $this->assertEmpty($classes);
 }
Beispiel #2
0
 public function makeTestPlan($filePath, $className)
 {
     // We need the following line for the subtle case where makeTestPlan
     // would be called bfore loadFile - we may instanciate $className
     // in this function, so we first make sure that the ClassDiscoverer
     // knows about the class as it can only discover it before it is
     // required for the first time.
     ClassDiscoverer::getDeclaredClasses($filePath);
     $executionPlan = new TestClassExecutionPlan();
     $executionPlan->setClassFilePath($filePath)->setClassName($className);
     $refl = new ReflectionClass($className);
     // Prepare dataProviderFilter
     $dataProviderFilter = null;
     if ($this->dataProviderFilter) {
         $parts = explode(':', $this->dataProviderFilter, 2);
         if (count($parts) === 2) {
             $methodFilter = $parts[0];
             $argumentsFilter = $parts[1];
         } else {
             $methodFilter = null;
             $argumentsFilter = $parts[0];
         }
         $dataProviderFilter = ['methodFilter' => $methodFilter, 'argumentsFilter' => explode(',', $argumentsFilter)];
     }
     foreach ($refl->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
         $dcp = new DocCommentParser($method->getDocComment());
         if (!$this->isTestMethod($method, $dcp)) {
             continue;
         }
         $dataProviderArguments = [[]];
         if ($dcp->hasOption('dataprovider')) {
             $dataProviderArguments = $executionPlan->call($dcp->getOption('dataprovider'));
             if ($dataProviderFilter && (!$dataProviderFilter['methodFilter'] || $method->getName() === $dataProviderFilter['methodFilter'])) {
                 $dataProviderArguments = array_filter($dataProviderArguments, function ($arguments) use($dataProviderFilter) {
                     foreach ($dataProviderFilter['argumentsFilter'] as $pos => $filter) {
                         if ($pos >= count($arguments)) {
                             return false;
                         }
                         if (!is_scalar($arguments[$pos])) {
                             return false;
                         }
                         $regexp = '/' . $filter . '/';
                         if (!preg_match($regexp, (string) $arguments[$pos])) {
                             return false;
                         }
                         return true;
                     }
                 });
             }
         }
         $testMethods = [];
         foreach ($dataProviderArguments as $arguments) {
             $testMethod = $this->newTestMethod($filePath, $className, $method, $dcp);
             $testMethod->setDataProviderArguments($arguments);
             $testMethods[] = $testMethod;
         }
         if ($dcp->hasOption('parallelize')) {
             $executionPlan->addTestMethods($testMethods);
         } else {
             foreach ($testMethods as $testMethod) {
                 $executionPlan->addTestMethod($testMethod);
             }
         }
     }
     return $executionPlan;
 }