public function FileTest::testFetchMultipleFiles in Migrate Plus 8.5
Same name and namespace in other branches
- 8.4 tests/src/Unit/data_fetcher/FileTest.php \Drupal\Tests\migrate_plus\Unit\data_fetcher\FileTest::testFetchMultipleFiles()
Test fetching multiple valid files.
File
- tests/
src/ Unit/ data_fetcher/ FileTest.php, line 121 - 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_fetcherCode
public function testFetchMultipleFiles() : void {
$number_of_files = 3;
$file_paths = [];
$file_names = [];
for ($i = 0; $i < $number_of_files; $i++) {
$file_name = 'file_' . $i . '.json';
$file_names[] = $file_name;
$file_paths[] = vfsStream::url(implode(DIRECTORY_SEPARATOR, [
self::BASE_DIRECTORY,
$file_name,
]));
}
$migration_config = $this->specificMigrationConfig + [
'urls' => $file_paths,
];
$plugin = new File($migration_config, $this->dataFetcherPluginId, $this->pluginDefinition);
for ($i = 0; $i < $number_of_files; $i++) {
$file_name = $file_names[$i];
$file_path = $file_paths[$i];
$tree = [
$file_name => $this->testData,
];
vfsStream::create($tree, $this->baseDir);
$expected = json_decode($this->testData);
$retrieved = json_decode($plugin
->getResponseContent($file_path));
$this
->assertEquals($expected, $retrieved);
}
}