You are here

public function FileTest::testFetchFile in Migrate Plus 8.4

Same name and namespace in other branches
  1. 8.5 tests/src/Unit/data_fetcher/FileTest.php \Drupal\Tests\migrate_plus\Unit\data_fetcher\FileTest::testFetchFile()

Test fetching a valid file.

File

tests/src/Unit/data_fetcher/FileTest.php, line 93
PHPUnit tests for the Migrate Plus File 'data fetcher' plugin.

Class

FileTest
@coversDefaultClass \Drupal\migrate_plus\Plugin\migrate_plus\data_fetcher\File

Namespace

Drupal\Tests\migrate_plus\Unit\data_fetcher

Code

public function testFetchFile() {
  $file_name = 'file.json';
  $file_path = vfsStream::url(implode(DIRECTORY_SEPARATOR, [
    self::BASE_DIRECTORY,
    $file_name,
  ]));
  $migration_config = $this->specificMigrationConfig + [
    'urls' => [
      $file_path,
    ],
  ];
  $plugin = new File($migration_config, $this->dataFetcherPluginId, $this->pluginDefinition);
  $tree = [
    $file_name => $this->testData,
  ];
  vfsStream::create($tree, $this->baseDir);
  $expected = json_decode($this->testData, TRUE);
  $retrieved = json_decode($plugin
    ->getResponseContent($file_path), TRUE);
  $this
    ->assertEquals($expected, $retrieved);
}