You are here

protected function CsvTestBase::loadFixture in Commerce Migrate 3.1.x

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/CsvTestBase.php \Drupal\Tests\commerce_migrate\Kernel\CsvTestBase::loadFixture()
  2. 3.0.x tests/src/Kernel/CsvTestBase.php \Drupal\Tests\commerce_migrate\Kernel\CsvTestBase::loadFixture()

Copy the source CSV files to the path in the migration.

Parameters

string|array $fixtures: The full pathname of the fixture.

1 call to CsvTestBase::loadFixture()
CsvTestBase::setUp in tests/src/Kernel/CsvTestBase.php

File

tests/src/Kernel/CsvTestBase.php, line 83

Class

CsvTestBase
Test base for migrations tests with CSV source file.

Namespace

Drupal\Tests\commerce_migrate\Kernel

Code

protected function loadFixture($fixtures) {
  if (is_string($fixtures)) {
    $fixtures = [
      $fixtures,
    ];
  }

  // Make sure the file destination directory exists.
  if (!file_exists($this->csvPath)) {
    $this->fs
      ->mkdir($this->csvPath, NULL, TRUE);
  }

  // Copy each fixture to the public directory.
  foreach ($fixtures as $fixture) {
    $filename = basename($fixture);
    $destination_uri = $this->csvPath . '/' . $filename;
    $file_system = \Drupal::service('file_system');
    if (!$file_system
      ->copy($fixture, $destination_uri)) {
      throw new MigrateException("Migration setup failed to copy source CSV file '{$fixture}' to '{$destination_uri}'.");
    }
  }
}