You are here

ModuleMockerTrait.php in Drupal 7 to 8/9 Module Upgrader 8

File

tests/src/Unit/ModuleMockerTrait.php
View source
<?php

namespace Drupal\Tests\drupalmoduleupgrader\Unit;

use org\bovigo\vfs\vfsStream;

/**
 * A trait for tests that need a mock module to work on.
 */
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;
  }

}

Traits

Namesort descending Description
ModuleMockerTrait A trait for tests that need a mock module to work on.