You are here

protected function PHPUnit_Util_Configuration::getTestSuite in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/phpunit/phpunit/src/Util/Configuration.php \PHPUnit_Util_Configuration::getTestSuite()

@since Method available since Release 3.4.0

Parameters

DOMElement $testSuiteNode:

Return value

PHPUnit_Framework_TestSuite

1 call to PHPUnit_Util_Configuration::getTestSuite()
PHPUnit_Util_Configuration::getTestSuiteConfiguration in vendor/phpunit/phpunit/src/Util/Configuration.php
Returns the test suite configuration.

File

vendor/phpunit/phpunit/src/Util/Configuration.php, line 881

Class

PHPUnit_Util_Configuration
Wrapper for the PHPUnit XML configuration file.

Code

protected function getTestSuite(DOMElement $testSuiteNode, $testSuiteFilter = null) {
  if ($testSuiteNode
    ->hasAttribute('name')) {
    $suite = new PHPUnit_Framework_TestSuite((string) $testSuiteNode
      ->getAttribute('name'));
  }
  else {
    $suite = new PHPUnit_Framework_TestSuite();
  }
  $exclude = array();
  foreach ($testSuiteNode
    ->getElementsByTagName('exclude') as $excludeNode) {
    $excludeFile = (string) $excludeNode->textContent;
    if ($excludeFile) {
      $exclude[] = $this
        ->toAbsolutePath($excludeFile);
    }
  }
  $fileIteratorFacade = new File_Iterator_Facade();
  foreach ($testSuiteNode
    ->getElementsByTagName('directory') as $directoryNode) {
    if ($testSuiteFilter && $directoryNode->parentNode
      ->getAttribute('name') != $testSuiteFilter) {
      continue;
    }
    $directory = (string) $directoryNode->textContent;
    if (empty($directory)) {
      continue;
    }
    if ($directoryNode
      ->hasAttribute('phpVersion')) {
      $phpVersion = (string) $directoryNode
        ->getAttribute('phpVersion');
    }
    else {
      $phpVersion = PHP_VERSION;
    }
    if ($directoryNode
      ->hasAttribute('phpVersionOperator')) {
      $phpVersionOperator = (string) $directoryNode
        ->getAttribute('phpVersionOperator');
    }
    else {
      $phpVersionOperator = '>=';
    }
    if (!version_compare(PHP_VERSION, $phpVersion, $phpVersionOperator)) {
      continue;
    }
    if ($directoryNode
      ->hasAttribute('prefix')) {
      $prefix = (string) $directoryNode
        ->getAttribute('prefix');
    }
    else {
      $prefix = '';
    }
    if ($directoryNode
      ->hasAttribute('suffix')) {
      $suffix = (string) $directoryNode
        ->getAttribute('suffix');
    }
    else {
      $suffix = 'Test.php';
    }
    $files = $fileIteratorFacade
      ->getFilesAsArray($this
      ->toAbsolutePath($directory), $suffix, $prefix, $exclude);
    $suite
      ->addTestFiles($files);
  }
  foreach ($testSuiteNode
    ->getElementsByTagName('file') as $fileNode) {
    if ($testSuiteFilter && $fileNode->parentNode
      ->getAttribute('name') != $testSuiteFilter) {
      continue;
    }
    $file = (string) $fileNode->textContent;
    if (empty($file)) {
      continue;
    }

    // Get the absolute path to the file
    $file = $fileIteratorFacade
      ->getFilesAsArray($this
      ->toAbsolutePath($file));
    if (!isset($file[0])) {
      continue;
    }
    $file = $file[0];
    if ($fileNode
      ->hasAttribute('phpVersion')) {
      $phpVersion = (string) $fileNode
        ->getAttribute('phpVersion');
    }
    else {
      $phpVersion = PHP_VERSION;
    }
    if ($fileNode
      ->hasAttribute('phpVersionOperator')) {
      $phpVersionOperator = (string) $fileNode
        ->getAttribute('phpVersionOperator');
    }
    else {
      $phpVersionOperator = '>=';
    }
    if (!version_compare(PHP_VERSION, $phpVersion, $phpVersionOperator)) {
      continue;
    }
    $suite
      ->addTestFile($file);
  }
  return $suite;
}