destruct example


        public function rebuildIfNeeded()
        {
            return $this->lazyLoadItself()->rebuildIfNeeded();
        }

        /** * {@inheritdoc} */
        public function destruct()
        {
            return $this->lazyLoadItself()->destruct();
        }

    }

}
$this->assertNotEmpty(\Drupal::cache()->get($cid), 'Cache entry was created.');

    // Trigger a cache miss for an offset.     $this->assertNotEmpty($registry->get('theme_test_template_test'), 'Offset was returned correctly from the theme registry.');
    // This will cause the ThemeRegistry class to write an updated version of     // the cache entry when it is destroyed, usually at the end of the request.     // Before that happens, manually delete the cache entry we created earlier     // so that the new entry is written from scratch.     \Drupal::cache()->delete($cid);

    // Destroy the class so that it triggers a cache write for the offset.     $registry->destruct();

    $this->assertNotEmpty(\Drupal::cache()->get($cid), 'Cache entry was created.');

    // Create a new instance of the class. Confirm that both the offset     // requested previously, and one that has not yet been requested are both     // available.     $registry = new ThemeRegistry($cid$cache$lock_backend['theme_registry']$this->container->get('module_handler')->isLoaded());
    $this->assertNotEmpty($registry->get('theme_test_template_test'), 'Offset was returned correctly from the theme registry');
    $this->assertNotEmpty($registry->get('theme_test_template_test_2'), 'Offset was returned correctly from the theme registry');
  }

  
->with('library_info:kitten_theme')
      ->willReturn(FALSE);
    $this->cache->expects($this->once())
      ->method('set')
      ->with('library_info:kitten_theme', ['test' => $this->libraryData], Cache::PERMANENT, ['library_info']);
    $this->lock->expects($this->once())
      ->method('release')
      ->with($lock_key);

    // This should get data and persist the key.     $this->libraryDiscoveryCollector->get('test');
    $this->libraryDiscoveryCollector->destruct();
  }

  /** * Tests library with an extend. * * @covers ::applyLibrariesExtend */
  public function testLibrariesExtend() {
    $this->activeTheme = $this->getMockBuilder(ActiveTheme::class)
      ->disableOriginalConstructor()
      ->getMock();
    
/** * 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(). */
  public static function providerTestInvalidCharacters() {
    return [
      // Nothing special.       ['foo', 'bar', 'baz'],
      

  public function onKernelTerminate(TerminateEvent $event) {
    foreach ($this->services as $id) {
      // Check if the service was initialized during this request, destruction       // is not necessary if the service was not used.       if ($this->container->initialized($id)) {
        $service = $this->container->get($id);
        $service->destruct();
      }
    }
  }

  /** * Registers the methods in this class that should be listeners. * * @return array * An array of event listener definitions. */
  public static function getSubscribedEvents(): array {
    
    // depend on the theme list, so invalidate those via the local tasks cache     // tag.     Cache::invalidateTags(['theme_registry', 'local_task']);
    return $this;
  }

  /** * {@inheritdoc} */
  public function destruct() {
    foreach ($this->runtimeRegistry as $runtime_registry) {
      $runtime_registry->destruct();
    }
  }

  /** * Gets all user functions grouped by the word before the first underscore. * * @param $prefixes * An array of function prefixes by which the list can be limited. * * @return array * Functions grouped by the first prefix. */


    $this->assertSame($expected_trail_ids$this->menuActiveTrail->getActiveTrailIds($data[2]));

    $this->cache->expects($this->once())
      ->method('set')
      // Ensure we normalize the serialized data by sorting them.       ->with('active-trail:route:baby_llama:route_parameters:' . serialize(['a' => 0, 'b' => 1]));
    $this->lock->expects($this->any())
      ->method('acquire')
      ->willReturn(TRUE);
    $this->menuActiveTrail->destruct();
  }

}
// Remove the user alias again, whitelist entry should be removed.     $path_alias_storage = $this->container->get('entity_type.manager')->getStorage('path_alias');
    $entities = $path_alias_storage->loadByProperties(['path' => '/user/1']);
    $path_alias_storage->delete($entities);
    $aliasManager->cacheClear();
    $this->assertNull($whitelist->get('user'));
    $this->assertTrue($whitelist->get('admin'));
    $this->assertNull($whitelist->get($this->randomMachineName()));

    // Destruct the whitelist so that the caches are written.     $whitelist->destruct();
    $this->assertEquals(1, $memoryCounterBackend->getCounter('set', 'path_alias_whitelist'));
    $memoryCounterBackend->resetCounter();

    // Re-initialize the whitelist using the same cache backend, should load     // from cache.     $whitelist = new AliasWhitelist('path_alias_whitelist', $memoryCounterBackend$this->container->get('lock')$this->container->get('state')$this->container->get('path_alias.repository'));
    $this->assertNull($whitelist->get('user'));
    $this->assertTrue($whitelist->get('admin'));
    $this->assertNull($whitelist->get($this->randomMachineName()));
    $this->assertEquals(1, $memoryCounterBackend->getCounter('get', 'path_alias_whitelist'));
    $this->assertEquals(0, $memoryCounterBackend->getCounter('set', 'path_alias_whitelist'));

    
$this->lock = $this->createMock('Drupal\Core\Lock\LockBackendInterface');
    $this->languageManager = $this->createMock('Drupal\Core\Language\LanguageManagerInterface');
    $this->requestStack = new RequestStack();
  }

  /** * Tests for \Drupal\locale\LocaleTranslation::destruct(). */
  public function testDestruct() {
    $translation = new LocaleTranslation($this->storage, $this->cache, $this->lock, $this->getConfigFactoryStub()$this->languageManager, $this->requestStack);
    // Prove that destruction works without errors when translations are empty.     $this->assertNull($translation->destruct());
  }

}
/** * Tests updating the cache when no changes were made. */
  public function testUpdateCacheNoChanges() {
    $this->lock->expects($this->never())
      ->method('acquire');
    $this->cacheBackend->expects($this->never())
      ->method('set');

    // Destruct the object to trigger the update data process.     $this->collector->destruct();
  }

  /** * Tests updating the cache after a set. */
  public function testUpdateCache() {
    $key = $this->randomMachineName();
    $value = $this->randomMachineName();

    $this->collector->setCacheMissData($key$value);
    $this->collector->get($key);

    
unset($this->translateEnglish);
    $this->translations = [];
  }

  /** * {@inheritdoc} */
  public function destruct() {
    foreach ($this->translations as $context) {
      foreach ($context as $lookup) {
        if ($lookup instanceof DestructableInterface) {
          $lookup->destruct();
        }
      }
    }
  }

}
Home | Imprint | This part of the site doesn't use cookies.