tmpDir example

/** * Creates a system-under-test and initialize a git repository for it. * * @param string $fixture_name * The name of the fixture to use from * core/tests/Drupal/Tests/Component/Scaffold/fixtures. * * @return string * The path to the fixture directory. */
  protected function createSutWithGit($fixture_name) {
    $this->fixturesDir = $this->fixtures->tmpDir($this->getName());
    $sut = $this->fixturesDir . '/' . $fixture_name;
    $replacements = ['SYMLINK' => 'false', 'PROJECT_ROOT' => $this->projectRoot];
    $this->fixtures->cloneFixtureProjects($this->fixturesDir, $replacements);
    // .gitignore files will not be managed unless there is a git repository.     $this->mustExec('git init', $sut);
    // Add some user info so git does not complain.     $this->mustExec('git config user.email "test@example.com"', $sut);
    $this->mustExec('git config user.name "Test User"', $sut);
    $this->mustExec('git add .', $sut);
    $this->mustExec('git commit -m "Initial commit."', $sut);
    // Run composer install, but suppress scaffolding.
$this->fixtures->createIsolatedComposerCacheDir();
  }

  /** * Tests upgrading the Composer Scaffold plugin. */
  public function testScaffoldUpgrade() {
    $composerVersionLine = exec('composer --version');
    if (str_contains($composerVersionLine, 'Composer version 2')) {
      $this->markTestSkipped('We cannot run the scaffold upgrade test with Composer 2 until we have a stable version of drupal/core-composer-scaffold to start from that we can install with Composer 2.x.');
    }
    $this->fixturesDir = $this->fixtures->tmpDir($this->getName());
    $replacements = ['SYMLINK' => 'false', 'PROJECT_ROOT' => $this->fixtures->projectRoot()];
    $this->fixtures->cloneFixtureProjects($this->fixturesDir, $replacements);
    $topLevelProjectDir = 'drupal-drupal';
    $sut = $this->fixturesDir . '/' . $topLevelProjectDir;

    // First step: set up the Scaffold plug in. Ensure that scaffold operation     // ran. This is more of a control than a test.     $this->mustExec("composer install --no-ansi", $sut);
    $this->assertScaffoldedFile($sut . '/sites/default/default.settings.php', FALSE, 'A settings.php fixture file scaffolded from the scaffold-override-fixture');

    // Next, bring back packagist.org and install core-composer-scaffold:8.8.0.

  protected function setUp(): void {
    $this->fileSystem = new Filesystem();
    $this->fixtures = new Fixtures();
    $this->fixtures->createIsolatedComposerCacheDir();
    $this->projectRoot = $this->fixtures->projectRoot();
    // The directory used for creating composer projects to test can be     // configured using the SCAFFOLD_FIXTURE_DIR environment variable. Otherwise     // a directory will be created in the system's temporary directory.     $this->fixturesDir = getenv('SCAFFOLD_FIXTURE_DIR');
    if (!$this->fixturesDir) {
      $this->fixturesDir = $this->fixtures->tmpDir($this->getName());
    }
  }

  /** * {@inheritdoc} */
  protected function tearDown(): void {
    // Remove any temporary directories et. al. that were created.     $this->fixtures->tearDown();
  }

  
/** * Creates a temporary directory. * * @param string $prefix * A prefix for the temporary directory name. * * @return string * Path to temporary directory */
  public function mkTmpDir($prefix) {
    $tmpDir = $this->tmpDir($prefix);
    $filesystem = new Filesystem();
    $filesystem->ensureDirectoryExists($tmpDir);
    return $tmpDir;
  }

  /** * Create an isolated cache directory for Composer. */
  public function createIsolatedComposerCacheDir() {
    $cacheDir = $this->mkTmpDir('composer-cache');
    putenv("COMPOSER_CACHE_DIR=$cacheDir");
  }
protected $fixtures;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->fileSystem = new Filesystem();
    $this->fixtures = new Fixtures();
    $this->fixtures->createIsolatedComposerCacheDir();
    $this->fixturesDir = $this->fixtures->tmpDir($this->getName());
    $replacements = ['SYMLINK' => 'false', 'PROJECT_ROOT' => $this->fixtures->projectRoot()];
    $this->fixtures->cloneFixtureProjects($this->fixturesDir, $replacements);
  }

  /** * {@inheritdoc} */
  protected function tearDown(): void {
    // Remove any temporary directories et. al. that were created.     $this->fixtures->tearDown();

    
Home | Imprint | This part of the site doesn't use cookies.