ApcuBackendTest.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace Drupal\KernelTests\Core\Cache;
  3. use Drupal\Core\Cache\ApcuBackend;
  4. /**
  5. * Tests the APCu cache backend.
  6. *
  7. * @group Cache
  8. * @requires extension apcu
  9. */
  10. class ApcuBackendTest extends GenericCacheBackendUnitTestBase {
  11. /**
  12. * {@inheritdoc}
  13. */
  14. protected function createCacheBackend($bin) {
  15. return new ApcuBackend($bin, $this->databasePrefix, \Drupal::service('cache_tags.invalidator.checksum'));
  16. }
  17. /**
  18. * {@inheritdoc}
  19. */
  20. protected function tearDown() {
  21. foreach ($this->cachebackends as $bin => $cachebackend) {
  22. $this->cachebackends[$bin]->removeBin();
  23. }
  24. parent::tearDown();
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function testSetGet() {
  30. parent::testSetGet();
  31. // Make sure entries are permanent (i.e. no TTL).
  32. $backend = $this->getCacheBackend($this->getTestBin());
  33. $key = $backend->getApcuKey('TEST8');
  34. $iterator = new \APCUIterator('/^' . $key . '/');
  35. foreach ($iterator as $item) {
  36. $this->assertEqual(0, $item['ttl']);
  37. $found = TRUE;
  38. }
  39. $this->assertTrue($found);
  40. }
  41. }