function SqliteDatabaseExcluderTest::testSqliteDatabaseFilesExcluded
Tests that SQLite database files are excluded from stage operations.
@dataProvider providerSqliteDatabaseFilesExcluded
Parameters
string $web_root: The web root that should be returned by the path locator. See \Drupal\package_manager\PathLocator::getWebRoot().
string $db_path: The path of the SQLite database, as it should be reported by the database connection. This can be a relative or absolute path; it does not need to actually exist.
string|false $expected_excluded_path: The path to the database, as it should be given to CollectPathsToExcludeEvent. If FALSE, the database is located outside the project and therefore is not excluded.
File
-
core/
modules/ package_manager/ tests/ src/ Kernel/ PathExcluder/ SqliteDatabaseExcluderTest.php, line 111
Class
- SqliteDatabaseExcluderTest
- @covers \Drupal\package_manager\PathExcluder\SqliteDatabaseExcluder @group package_manager @internal
Namespace
Drupal\Tests\package_manager\Kernel\PathExcluderCode
public function testSqliteDatabaseFilesExcluded(string $web_root, string $db_path, string|false $expected_excluded_path) : void {
/** @var \Drupal\package_manager_bypass\MockPathLocator $path_locator */
$path_locator = $this->container
->get(PathLocator::class);
$project_root = $path_locator->getProjectRoot();
// Set the mocked web root, keeping everything else as-is.
$path_locator->setPaths($project_root, $path_locator->getVendorDirectory(), $web_root, $path_locator->getStagingRoot());
$db_path = str_replace('<PROJECT_ROOT>', $project_root, $db_path);
$this->mockDatabase
->getConnectionOptions()
->willReturn([
'database' => $db_path,
])
->shouldBeCalled();
$event = new CollectPathsToExcludeEvent($this->createStage(), $path_locator, $this->container
->get(PathFactoryInterface::class));
$actual_excluded_paths = $this->container
->get('event_dispatcher')
->dispatch($event)
->getAll();
if (is_string($expected_excluded_path)) {
$expected_exclusions = [
$expected_excluded_path,
$expected_excluded_path . '-shm',
$expected_excluded_path . '-wal',
];
$this->assertEmpty(array_diff($expected_exclusions, $actual_excluded_paths));
}
else {
// The path of the database should not appear anywhere in the list of
// excluded paths.
$this->assertStringNotContainsString($db_path, serialize($actual_excluded_paths));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.