You are here

public function FileCopyTest::testSuccessfulReuse in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php \Drupal\Tests\migrate\Kernel\process\FileCopyTest::testSuccessfulReuse()
  2. 9 core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php \Drupal\Tests\migrate\Kernel\process\FileCopyTest::testSuccessfulReuse()

Tests successful file reuse.

@dataProvider providerSuccessfulReuse

Parameters

string $source_path: Source path to copy from.

string $destination_path: The destination path to copy to.

File

core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php, line 87

Class

FileCopyTest
Tests the file_copy process plugin.

Namespace

Drupal\Tests\migrate\Kernel\process

Code

public function testSuccessfulReuse($source_path, $destination_path) {
  $file_reuse = $this
    ->doTransform($source_path, $destination_path);
  clearstatcache(TRUE, $destination_path);
  $timestamp = (new \SplFileInfo($file_reuse))
    ->getMTime();
  $this
    ->assertIsInt($timestamp);

  // We need to make sure the modified timestamp on the file is sooner than
  // the attempted migration.
  sleep(1);
  $configuration = [
    'file_exists' => 'use existing',
  ];
  $this
    ->doTransform($source_path, $destination_path, $configuration);
  clearstatcache(TRUE, $destination_path);
  $modified_timestamp = (new \SplFileInfo($destination_path))
    ->getMTime();
  $this
    ->assertEquals($timestamp, $modified_timestamp);
  $this
    ->doTransform($source_path, $destination_path);
  clearstatcache(TRUE, $destination_path);
  $modified_timestamp = (new \SplFileInfo($destination_path))
    ->getMTime();
  $this
    ->assertGreaterThan($timestamp, $modified_timestamp);
}