ParaTest\Runners\PHPUnit\Configuration::getSuiteByName PHP Method

getSuiteByName() public method

Return the contents of the nodes contained in a PHPUnit configuration
public getSuiteByName ( string $suiteName ) : SuitePath[] | null
$suiteName string
return SuitePath[] | null
    public function getSuiteByName($suiteName)
    {
        $nodes = $this->xml->xpath(sprintf('//testsuite[@name="%s"]', $suiteName));
        $suites = array();
        $excludedPaths = array();
        while (list(, $node) = each($nodes)) {
            foreach ($this->availableNodes as $nodeName) {
                foreach ($node->{$nodeName} as $nodeContent) {
                    switch ($nodeName) {
                        case 'exclude':
                            foreach ($this->getSuitePaths((string) $nodeContent) as $excludedPath) {
                                $excludedPaths[$excludedPath] = $excludedPath;
                            }
                            break;
                        case 'testsuite':
                            $suites = array_merge_recursive($suites, $this->getSuiteByName((string) $nodeContent));
                            break;
                        case 'directory':
                            // Replicate behaviour of PHPUnit
                            // if a directory is included and excluded at the same time, then it is considered included
                            foreach ($this->getSuitePaths((string) $nodeContent) as $dir) {
                                if (array_key_exists($dir, $excludedPaths)) {
                                    unset($excludedPaths[$dir]);
                                }
                            }
                            // not breaking on purpose
                        // not breaking on purpose
                        default:
                            foreach ($this->getSuitePaths((string) $nodeContent) as $path) {
                                $suites[(string) $node['name']][] = new SuitePath($path, $excludedPaths, $nodeContent->attributes()->suffix);
                            }
                            break;
                    }
                }
            }
        }
        return $suites;
    }

Usage Example

Example #1
0
 /**
  * Populates the loaded suite collection. Will load suites
  * based off a phpunit xml configuration or a specified path
  *
  * @param string $path
  * @throws \RuntimeException
  */
 public function load($path = '')
 {
     if (is_object($this->options) && isset($this->options->filtered['configuration'])) {
         $configuration = $this->options->filtered['configuration'];
     } else {
         $configuration = new Configuration('');
     }
     if ($path) {
         $testFileLoader = new TestFileLoader($this->options);
         $this->files = array_merge($this->files, $testFileLoader->loadPath($path));
     } elseif (isset($this->options->testsuite) && $this->options->testsuite) {
         foreach ($configuration->getSuiteByName($this->options->testsuite) as $suite) {
             foreach ($suite as $suitePath) {
                 $testFileLoader = new TestFileLoader($this->options);
                 $this->files = array_merge($this->files, $testFileLoader->loadSuitePath($suitePath));
             }
         }
     } elseif ($suites = $configuration->getSuites()) {
         foreach ($suites as $suite) {
             foreach ($suite as $suitePath) {
                 $testFileLoader = new TestFileLoader($this->options);
                 $this->files = array_merge($this->files, $testFileLoader->loadSuitePath($suitePath));
             }
         }
     }
     if (!$this->files) {
         throw new \RuntimeException("No path or configuration provided (tests must end with Test.php)");
     }
     $this->files = array_unique($this->files);
     // remove duplicates
     $this->initSuites();
 }