function InstallerRedirectTraitTest::testShouldRedirectToInstaller
@covers ::shouldRedirectToInstaller
@dataProvider providerShouldRedirectToInstaller
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Installer/ InstallerRedirectTraitTest.php, line 72
Class
- InstallerRedirectTraitTest
- @coversDefaultClass \Drupal\Core\Installer\InstallerRedirectTrait[[api-linebreak]]
Namespace
Drupal\KernelTests\Core\InstallerCode
public function testShouldRedirectToInstaller($expected, $exception, $connection, $connection_info, $sequences_table_exists = TRUE) : void {
try {
throw new $exception();
} catch (\Exception $e) {
// Mock the trait.
$trait = $this->getMockBuilder(InstallerRedirectTraitMockableClass::class)
->onlyMethods([
'isCli',
])
->getMock();
// Make sure that the method thinks we are not using the cli.
$trait->expects($this->any())
->method('isCli')
->willReturn(FALSE);
// Un-protect the method using reflection.
$method_ref = new \ReflectionMethod($trait, 'shouldRedirectToInstaller');
// Mock the database connection info.
$db = $this->getMockForAbstractClass(Database::class);
$property_ref = new \ReflectionProperty($db, 'databaseInfo');
$property_ref->setValue($db, [
'default' => $connection_info,
]);
if ($connection) {
// Mock the database connection.
$connection = $this->getMockBuilder(Connection::class)
->disableOriginalConstructor()
->onlyMethods([
'schema',
])
->getMockForAbstractClass();
if ($connection_info) {
// Mock the database schema class.
$schema = $this->getMockBuilder(Schema::class)
->disableOriginalConstructor()
->onlyMethods([
'tableExists',
])
->getMockForAbstractClass();
$schema->expects($this->any())
->method('tableExists')
->with('sequences')
->willReturn($sequences_table_exists);
$connection->expects($this->any())
->method('schema')
->willReturn($schema);
}
}
else {
// Set the database connection if there is none.
$connection = NULL;
}
// Call shouldRedirectToInstaller.
$this->assertSame($expected, $method_ref->invoke($trait, $e, $connection));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.