CacheCollectorHelper example

/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->cacheBackend = $this->createMock('Drupal\Core\Cache\CacheBackendInterface');
    $this->cacheTagsInvalidator = $this->createMock('Drupal\Core\Cache\CacheTagsInvalidatorInterface');
    $this->lock = $this->createMock('Drupal\Core\Lock\LockBackendInterface');
    $this->cid = $this->randomMachineName();
    $this->collector = new CacheCollectorHelper($this->cid, $this->cacheBackend, $this->lock);

    $this->getContainerWithCacheTagsInvalidator($this->cacheTagsInvalidator);
  }

  /** * Tests the resolve cache miss function. */
  public function testResolveCacheMiss() {
    $key = $this->randomMachineName();
    $value = $this->randomMachineName();
    $this->collector->setCacheMissData($key$value);

    
    $container
      ->register('lock', 'Drupal\Core\Lock\DatabaseLockBackend')
      ->addArgument(new Reference('database'));
  }

  /** * Tests setting and invalidating. * * @dataProvider providerTestInvalidCharacters */
  public function testCacheCollector($cid$key$value) {
    $collector = new CacheCollectorHelper($cid$this->container->get('cache.default')$this->container->get('lock'));
    $this->assertNull($collector->get($key));
    $collector->set($key$value);
    $this->assertEquals($value$collector->get($key));
    $collector->destruct();
    // @todo Shouldn't this be empty after destruction?     $this->assertEquals($value$collector->get($key));
  }

  /** * Data provider for ::testCacheCollector(). */
  
Home | Imprint | This part of the site doesn't use cookies.