function UpdateHookRegistryTest::testGetInstalledVersion

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Update/UpdateHookRegistryTest.php \Drupal\Tests\Core\Update\UpdateHookRegistryTest::testGetInstalledVersion()
  2. 11.x core/tests/Drupal/Tests/Core/Update/UpdateHookRegistryTest.php \Drupal\Tests\Core\Update\UpdateHookRegistryTest::testGetInstalledVersion()

@covers ::getInstalledVersion @covers ::getAllInstalledVersions @covers ::setInstalledVersion @covers ::deleteInstalledVersion

File

core/tests/Drupal/Tests/Core/Update/UpdateHookRegistryTest.php, line 119

Class

UpdateHookRegistryTest
@coversDefaultClass \Drupal\Core\Update\UpdateHookRegistry @group Update

Namespace

Drupal\Tests\Core\Update

Code

public function testGetInstalledVersion() : void {
    $versions = [
        'module1' => 1,
        'module2' => 20,
        'module3' => 3000,
    ];
    $this->keyValueStore
        ->method('getAll')
        ->willReturnCallback(static function () use (&$versions) {
        return $versions;
    });
    $this->keyValueStore
        ->method('get')
        ->willReturnCallback(static function ($key) use (&$versions) {
        return $versions[$key];
    });
    $this->keyValueStore
        ->method('delete')
        ->willReturnCallback(static function ($key) use (&$versions) {
        $versions[$key] = UpdateHookRegistry::SCHEMA_UNINSTALLED;
    });
    $this->keyValueStore
        ->method('set')
        ->willReturnCallback(static function ($key, $value) use (&$versions) {
        $versions[$key] = $value;
    });
    $update_registry = new UpdateHookRegistry([], $this->keyValueFactory);
    $this->assertSame(3000, $update_registry->getInstalledVersion('module3'));
    $update_registry->setInstalledVersion('module3', 3001);
    $this->assertSame(3001, $update_registry->getInstalledVersion('module3'));
    $this->assertSame($versions, $update_registry->getAllInstalledVersions());
    $update_registry->deleteInstalledVersion('module3');
    $this->assertSame(UpdateHookRegistry::SCHEMA_UNINSTALLED, $update_registry->getInstalledVersion('module3'));
}

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