You are here

private function Tests::extractModules in Drupal 7 to 8/9 Module Upgrader 8

Extracts every module required by a web test by scanning its calls to parent::setUp().

Parameters

\Pharborist\Objects\ClassNode $test:

Return value

string[] Array of modules set up by this module.

1 call to Tests::extractModules()
Tests::setModules in src/Plugin/DMU/Converter/Tests.php
Sets the test's $modules property.

File

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

Class

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

Namespace

Drupal\drupalmoduleupgrader\Plugin\DMU\Converter

Code

private function extractModules(ClassNode $test) {
  $modules = [];
  $test
    ->find(Filter::isClassMethodCall('parent', 'setUp'))
    ->filter(function (ClassMethodCallNode $call) {
    return sizeof($call
      ->getArguments()) > 0;
  })
    ->each(function (ClassMethodCallNode $call) use (&$modules) {
    foreach ($call
      ->getArguments() as $argument) {
      if ($argument instanceof StringNode) {
        $modules[] = $argument
          ->toValue();
      }
    }
    $call
      ->clearArguments();
  });
  return array_unique($modules);
}