/** * Tests whether __construct() works as expected. * * @return void */ public function testInitialization() { $cacheItem = new BasicCacheItem('key'); $this->assertSame('key', $cacheItem->getKey()); $this->assertNull($cacheItem->get()); $this->assertTrue($cacheItem->isHit()); $this->assertNotNull($cacheItem->getExpirationTime()); $cacheItem = new BasicCacheItem('key', 42, true); $this->assertSame('key', $cacheItem->getKey()); $this->assertSame(42, $cacheItem->get()); $this->assertTrue($cacheItem->isHit()); $this->assertNotNull($cacheItem->getExpirationTime()); $cacheItem = new BasicCacheItem('key', null, false); $this->assertSame('key', $cacheItem->getKey()); $this->assertNull($cacheItem->get()); $this->assertFalse($cacheItem->isHit()); $this->assertNotNull($cacheItem->getExpirationTime()); $cacheItem = new BasicCacheItem('key', 42, true, new DateInterval('PT5M')); $this->assertSame('key', $cacheItem->getKey()); $this->assertSame(42, $cacheItem->get()); $this->assertTrue($cacheItem->isHit()); $this->assertNotNull($cacheItem->getExpirationTime()); $this->assertTrue($cacheItem->getExpirationTime() > DateUtil::getCurrentUtcDateTime()->add(new DateInterval('PT4M'))); $this->assertTrue($cacheItem->getExpirationTime() < DateUtil::getCurrentUtcDateTime()->add(new DateInterval('PT6M'))); $expirationTime = DateUtil::getUtcDateTimeByTimestamp(time() - 60); $storageItem = new BasicCacheItem('key', 42, false, new DateInterval('PT5M'), $expirationTime); $this->assertSame('key', $storageItem->getKey()); $this->assertNull($storageItem->get()); $this->assertFalse($storageItem->isHit()); $this->assertSame($expirationTime->getTimestamp(), $storageItem->getExpirationTime()->getTimestamp()); }
/** * Tests whether getUtcDateTimeByTimestamp() works as expected. * * @return void */ public function testGetUtcDateTimeByTimestamp() { $timestamp = time() + 60; $dateTime = DateUtil::getUtcDateTimeByTimestamp($timestamp); $this->assertSame('UTC', $dateTime->getTimezone()->getName()); $this->assertSame(0, $dateTime->getOffset()); $this->assertSame($timestamp, $dateTime->getTimestamp()); }
/** * Tests whether __construct() works as expected. * * @return void */ public function testInitialization() { $storageItem = new BasicStorageItem('key'); $this->assertSame('key', $storageItem->getKey()); $this->assertNull($storageItem->getValue()); $this->assertNull($storageItem->getExpirationTime()); $storageItem = new BasicStorageItem('key', 42); $this->assertSame('key', $storageItem->getKey()); $this->assertSame(42, $storageItem->getValue()); $this->assertNull($storageItem->getExpirationTime()); $storageItem = new BasicStorageItem('key', 42, new DateInterval('PT5M')); $this->assertSame('key', $storageItem->getKey()); $this->assertSame(42, $storageItem->getValue()); $this->assertNotNull($storageItem->getExpirationTime()); $expirationTime = DateUtil::getUtcDateTimeByTimestamp(time() - 60); $storageItem = new BasicStorageItem('key', 42, new DateInterval('PT5M'), $expirationTime); $this->assertSame('key', $storageItem->getKey()); $this->assertSame(42, $storageItem->getValue()); $this->assertSame($expirationTime->getTimestamp(), $storageItem->getExpirationTime()->getTimestamp()); }