function LegacyFileTest::testMove

Tests the file_copy deprecation and legacy behavior.

File

core/modules/file/tests/src/Kernel/LegacyFileTest.php, line 76

Class

LegacyFileTest
Tests deprecated file functions.

Namespace

Drupal\Tests\file\Kernel

Code

public function testMove() {
    $this->expectDeprecation('file_move is deprecated in drupal:9.3.0 and will be removed in drupal:10.0.0. Use \\Drupal\\file\\FileRepositoryInterface::move() instead. See https://www.drupal.org/node/3223520');
    $contents = $this->randomMachineName(10);
    $source = $this->createFile(NULL, $contents);
    $desired_uri = 'public://' . $this->randomMachineName();
    // Clone the object so we don't have to worry about the function changing
    // our reference copy.
    $result = file_move(clone $source, $desired_uri, FileSystemInterface::EXISTS_ERROR);
    // Check the return status and that the contents have not changed.
    $this->assertFileNotExists($source->getFileUri());
    $this->assertEquals($contents, file_get_contents($result->getFileUri()));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.