function FileLegacyTest::testFileUrlDeprecation

Tests that File::url() is deprecated.

@expectedDeprecation File entities returning the URL to the physical file in File::url() is deprecated, use $file->createFileUrl() instead. See https://www.drupal.org/node/3019830

File

core/modules/file/tests/src/Kernel/FileLegacyTest.php, line 40

Class

FileLegacyTest
Tests file deprecations.

Namespace

Drupal\Tests\file\Kernel

Code

public function testFileUrlDeprecation() {
    file_put_contents('public://example.txt', $this->randomMachineName());
    $file = File::create([
        'uri' => 'public://example.txt',
    ]);
    $file->save();
    $this->assertEquals($file->createFileUrl(FALSE), $file->url());
}

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