function LegacyFileTest::testCopy
Tests the file_copy deprecation and legacy behavior.
File
-
core/
modules/ file/ tests/ src/ Kernel/ LegacyFileTest.php, line 57
Class
- LegacyFileTest
- Tests deprecated file functions.
Namespace
Drupal\Tests\file\KernelCode
public function testCopy() {
$this->expectDeprecation('file_copy is deprecated in drupal:9.3.0 and will be removed in drupal:10.0.0. Use \\Drupal\\file\\FileRepositoryInterface::copy() 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_copy(clone $source, $desired_uri, FileSystemInterface::EXISTS_ERROR);
// Check the return status and that the contents have not changed.
$this->assertNotFalse($result, 'File copied successfully.');
$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.