BackendExpireTests.php in Supercache 2.0.x
File
src/Tests/Generic/Cache/BackendExpireTests.php
View source
<?php
namespace Drupal\supercache\Tests\Generic\Cache;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Component\Utility\Unicode;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Database\Database;
use Drupal\Core\Site\Settings;
class BackendExpireTests extends BackendGeneralTestCase {
public static function getInfo() {
return [
'name' => 'Expire tests',
'description' => 'Ensure that cache items properly expire.',
'group' => 'Couchbase',
];
}
public function testExpirations() {
$name = 'test-data';
$value = 'this is the data';
$this->backend
->set($name, $value, time() + 3);
$this
->assertExists('Item exists', $value, $name, $this->backend);
$this->backend2
->set($name, $value, time() + 7);
$this
->assertExists('Item exists', $value, $name, $this->backend2);
sleep(5);
$this
->refreshRequestTime($this->backend);
$this
->assertRemoved('Item expired', $name, $this->backend);
$this
->assertExists('Item exists', $value, $name, $this->backend2);
sleep(5);
$this
->refreshRequestTime($this->backend2);
$this
->assertRemoved('Item expired', $name, $this->backend2);
$this->backend
->set($name, $value, \Drupal\Core\Cache\Cache::PERMANENT);
sleep(5);
$this
->assertExists('Item exists', $value, $name, $this->backend);
}
}