function LegacyFileTest::testDatabaseFileUsageBackendConstruct

Tests passing legacy arguments to DatabaseFileUsageBackend::__construct().

@expectedDeprecation Passing the database connection as the first argument to Drupal\file\FileUsage\DatabaseFileUsageBackend::__construct is deprecated in drupal:8.8.0 and will throw a fatal error in drupal:9.0.0. Pass the config factory first. See https://www.drupal.org/node/3070148

Throws

\ReflectionException

File

core/modules/file/tests/src/Unit/LegacyFileTest.php, line 61

Class

LegacyFileTest
Provides unit tests for file module deprecation errors.

Namespace

Drupal\Tests\file\Unit

Code

public function testDatabaseFileUsageBackendConstruct() {
    $connection = $this->prophesize(Connection::class)
        ->reveal();
    $database_file_usage = new DatabaseFileUsageBackend($connection);
    $reflection = new \ReflectionObject($database_file_usage);
    $reflection_config = $reflection->getProperty('configFactory');
    $reflection_config->setAccessible(TRUE);
    $reflection_connection = $reflection->getProperty('connection');
    $reflection_connection->setAccessible(TRUE);
    $reflection_table_name = $reflection->getProperty('tableName');
    $reflection_table_name->setAccessible(TRUE);
    $this->assertSame($this->configFactory, $reflection_config->getValue($database_file_usage));
    $this->assertSame($connection, $reflection_connection->getValue($database_file_usage));
    $this->assertSame('file_usage', $reflection_table_name->getValue($database_file_usage));
    $database_file_usage_test_table = new DatabaseFileUsageBackend($connection, 'test_table');
    $this->assertSame('test_table', $reflection_table_name->getValue($database_file_usage_test_table));
    $this->expectException(\InvalidArgumentException::class);
    $database_file_usage_exception = new DatabaseFileUsageBackend('Invalid Argument');
}

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