function StagedDBUpdateValidatorTest::setUp

Overrides PackageManagerKernelTestBase::setUp

File

core/modules/package_manager/tests/src/Kernel/StagedDBUpdateValidatorTest.php, line 20

Class

StagedDBUpdateValidatorTest
@covers \Drupal\package_manager\Validator\SandboxDatabaseUpdatesValidator @group package_manager @internal

Namespace

Drupal\Tests\package_manager\Kernel

Code

protected function setUp() : void {
    parent::setUp();
    $this->container
        ->get('theme_installer')
        ->install([
        'stark',
    ]);
    $this->assertFalse($this->container
        ->get('module_handler')
        ->moduleExists('views'));
    $this->assertFalse($this->container
        ->get('theme_handler')
        ->themeExists('olivero'));
    // Ensure that all the extensions we're testing with have database update
    // files in the active directory.
    $active_dir = $this->container
        ->get(PathLocator::class)
        ->getProjectRoot();
    // System and Stark are installed, so they are used to test what happens
    // when database updates are detected in installed extensions. Views and
    // Olivero are not installed, so they are used to test what happens when
    // non-installed extensions have database updates.
    $extensions = [
        'core/modules/system',
        'core/themes/stark',
        'core/modules/views',
        'core/themes/olivero',
    ];
    foreach ($extensions as $extension_path) {
        $extension_path = $active_dir . '/' . $extension_path;
        mkdir($extension_path, 0777, TRUE);
        $extension_name = basename($extension_path);
        // Ensure each extension has a .install and a .post_update.php file with
        // an empty update function in it.
        foreach ([
            'install',
            'post_update.php',
        ] as $suffix) {
            $function_name = match ($suffix) {    'install' => $extension_name . '_update_1000',
                'post_update.php' => $extension_name . '_post_update_test',
            
            };
            file_put_contents("{$extension_path}/{$extension_name}.{$suffix}", "<?php\nfunction {$function_name}() {}");
        }
    }
}

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