CacheDataCollectorTest.php in Devel 4.x
File
webprofiler/tests/src/Unit/DataCollector/CacheDataCollectorTest.php
View source
<?php
namespace Drupal\Tests\webprofiler\Unit\DataCollector;
use Drupal\webprofiler\Cache\CacheBackendWrapper;
use Drupal\webprofiler\DataCollector\CacheDataCollector;
class CacheDataCollectorTest extends DataCollectorBaseTest {
private $cacheDataCollector;
private $cacheBackendInterface;
public function setUp() {
$this->cacheDataCollector = new CacheDataCollector();
$this->cacheBackendInterface = $this
->createMock('Drupal\\Core\\Cache\\CacheBackendInterface');
}
public function testCacheCollectorMiss() {
$this->cacheBackendInterface
->expects($this
->once())
->method('get')
->will($this
->returnValue(FALSE));
$cacheBackendWrapper = new CacheBackendWrapper($this->cacheDataCollector, $this->cacheBackendInterface, 'default');
$cache = $cacheBackendWrapper
->get('cache_id');
$this
->assertFalse($cache);
$this
->assertEquals(1, $this->cacheDataCollector
->getCacheMissesCount());
}
public function testCacheCollectorHit() {
$cache = new \stdClass();
$cache->cid = 'cache_id';
$cache->expire = 1;
$cache->tags = [
'tag1',
'tag2',
];
$this->cacheBackendInterface
->expects($this
->once())
->method('get')
->will($this
->returnValue($cache));
$cacheBackendWrapper = new CacheBackendWrapper($this->cacheDataCollector, $this->cacheBackendInterface, 'default');
$cache2 = $cacheBackendWrapper
->get('cache_id');
$this
->assertNotNull($cache2);
$this
->assertEquals(1, $this->cacheDataCollector
->getCacheHitsCount());
}
}