You are here

public function Tests::convert in Drupal 7 to 8/9 Module Upgrader 8

Performs required conversions.

Parameters

TargetInterface $target: The target module to convert.

Overrides ConverterInterface::convert

File

src/Plugin/DMU/Converter/Tests.php, line 43

Class

Tests
Plugin annotation @Converter( id = "tests", description = @Translation("Modifies test classes.") )

Namespace

Drupal\drupalmoduleupgrader\Plugin\DMU\Converter

Code

public function convert(TargetInterface $target) {
  $this->target = $target;
  $mapping = [
    'DrupalWebTestCase' => 'convertWeb',
    'AJAXTestCase' => 'convertAjax',
  ];
  foreach ($mapping as $parent_class => $convert_method) {
    $test_files = $target
      ->getIndexer('class')
      ->getQuery([
      'file',
    ])
      ->condition('parent', $parent_class)
      ->execute()
      ->fetchCol();
    foreach ($test_files as $test_file) {

      /** @var \Pharborist\Objects\Classnode[] $tests */
      $tests = $target
        ->open($test_file)
        ->find(Filter::isInstanceOf('\\Pharborist\\Objects\\SingleInheritanceNode'))
        ->toArray();
      foreach ($tests as $test) {
        if ((string) $test
          ->getExtends() === $parent_class) {
          $this
            ->{$convert_method}($test);
        }
      }
    }
  }
}