class UpdateHookRegistryTest
@coversDefaultClass \Drupal\Core\Update\UpdateHookRegistry
      
    
@group Update
Hierarchy
- class \Drupal\Tests\UnitTestCase uses \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait extends \PHPUnit\Framework\TestCase- class \Drupal\Tests\Core\Update\UpdateHookRegistryTest extends \Drupal\Tests\UnitTestCase
 
Expanded class hierarchy of UpdateHookRegistryTest
File
- 
              core/tests/ Drupal/ Tests/ Core/ Update/ UpdateHookRegistryTest.php, line 64 
Namespace
Drupal\Tests\Core\UpdateView source
class UpdateHookRegistryTest extends UnitTestCase {
  
  /**
   * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface|\PHPUnit\Framework\MockObject\MockObject
   */
  protected $keyValueStore;
  
  /**
   * @var \Drupal\Core\KeyValueStore\KeyValueFactoryInterface|\PHPUnit\Framework\MockObject\MockObject
   */
  protected $keyValueFactory;
  
  /**
   * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface|\PHPUnit\Framework\MockObject\MockObject
   */
  protected KeyValueStoreInterface $equivalentUpdatesStore;
  
  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $this->keyValueFactory = $this->createMock(KeyValueFactoryInterface::class);
    $this->keyValueStore = $this->createMock(KeyValueStoreInterface::class);
    $this->equivalentUpdatesStore = $this->createMock(KeyValueStoreInterface::class);
    $this->keyValueFactory
      ->method('get')
      ->willReturnMap([
      [
        'system.schema',
        $this->keyValueStore,
      ],
      [
        'core.equivalent_updates',
        $this->equivalentUpdatesStore,
      ],
    ]);
  }
  
  /**
   * @covers ::getAvailableUpdates
   */
  public function testGetVersions() : void {
    $module_name = 'drupal\\tests\\core\\update\\under_test';
    $update_registry = new UpdateHookRegistry([], $this->keyValueFactory);
    // Only under_test_update_X - passes through the filter.
    $expected = [
      1,
      20,
      3000,
    ];
    $actual = $update_registry->getAvailableUpdates($module_name);
    $this->assertSame($expected, $actual);
  }
  
  /**
   * @covers ::getInstalledVersion
   * @covers ::getAllInstalledVersions
   * @covers ::setInstalledVersion
   * @covers ::deleteInstalledVersion
   */
  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'));
  }
}Members
| Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overriden Title | Overrides | 
|---|---|---|---|---|---|---|
| PhpUnitWarnings::$deprecationWarnings | private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |||
| PhpUnitWarnings::addWarning | public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |||
| RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |||
| RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |||
| RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |||
| RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |||
| RandomGeneratorTrait::randomStringValidate | Deprecated | public | function | Callback for random string validation. | ||
| UnitTestCase::$root | protected | property | The app root. | 1 | ||
| UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |||
| UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |||
| UnitTestCase::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | |||
| UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |||
| UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |||
| UnitTestCase::setUpBeforeClass | public static | function | ||||
| UnitTestCase::__get | public | function | ||||
| UpdateHookRegistryTest::$equivalentUpdatesStore | protected | property | ||||
| UpdateHookRegistryTest::$keyValueFactory | protected | property | ||||
| UpdateHookRegistryTest::$keyValueStore | protected | property | ||||
| UpdateHookRegistryTest::setUp | protected | function | Overrides UnitTestCase::setUp | |||
| UpdateHookRegistryTest::testGetInstalledVersion | public | function | @covers ::getInstalledVersion[[api-linebreak]] @covers ::getAllInstalledVersions[[api-linebreak]] @covers ::setInstalledVersion[[api-linebreak]] @covers ::deleteInstalledVersion[[api-linebreak]] | |||
| UpdateHookRegistryTest::testGetVersions | public | function | @covers ::getAvailableUpdates[[api-linebreak]] | 
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
