You are here

trait ModuleMockerTrait in Drupal 7 to 8/9 Module Upgrader 8

A trait for tests that need a mock module to work on.

Hierarchy

File

tests/src/Unit/ModuleMockerTrait.php, line 10

Namespace

Drupal\Tests\drupalmoduleupgrader\Unit
View source
trait ModuleMockerTrait {
  protected function mockModule($id) {

    // Create a virtual (in-memory) directory for the module, and touch
    // a few empty files. Tests should fill in the code of the module
    // according to their own needs.
    $dir = vfsStream::setup($id);
    vfsStream::newFile($id . '.module')
      ->at($dir);
    vfsStream::newFile($id . '.info')
      ->at($dir);
    vfsStream::newFile($id . '.install')
      ->at($dir);
    vfsStream::newFile($id . '.test')
      ->at($dir);
    vfsStream::newDirectory('src')
      ->at($dir);
    $config_dir = vfsStream::newDirectory('config')
      ->at($dir);
    vfsStream::newDirectory('install')
      ->at($config_dir);
    vfsStream::newDirectory('optional')
      ->at($config_dir);
    vfsStream::newDirectory('schema')
      ->at($config_dir);
    return $dir;
  }

}

Members