class CacheDataCollectorTest

@coversDefaultClass \Drupal\webprofiler\DataCollector\CacheDataCollector

@group webprofiler

Hierarchy

  • class \Drupal\Tests\webprofiler\Unit\DataCollector\DataCollectorBaseTest extends \Drupal\Tests\UnitTestCase
    • class \Drupal\Tests\webprofiler\Unit\DataCollector\CacheDataCollectorTest extends \Drupal\Tests\webprofiler\Unit\DataCollector\DataCollectorBaseTest

Expanded class hierarchy of CacheDataCollectorTest

File

webprofiler/tests/src/Unit/DataCollector/CacheDataCollectorTest.php, line 13

Namespace

Drupal\Tests\webprofiler\Unit\DataCollector
View source
class CacheDataCollectorTest extends DataCollectorBaseTest {
    
    /**
     * @var \Drupal\webprofiler\DataCollector\CacheDataCollector
     */
    private $cacheDataCollector;
    
    /**
     * @var \PHPUnit_Framework_MockObject_MockObject
     */
    private $cacheBackendInterface;
    
    /**
     * {@inheritdoc}
     */
    public function setUp() {
        $this->cacheDataCollector = new CacheDataCollector();
        $this->cacheBackendInterface = $this->getMock('Drupal\\Core\\Cache\\CacheBackendInterface');
    }
    
    /**
     * Tests the collection of a cache miss.
     */
    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());
    }
    
    /**
     * Tests the collection of a cache hit.
     */
    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());
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
CacheDataCollectorTest::$cacheBackendInterface private property
CacheDataCollectorTest::$cacheDataCollector private property
CacheDataCollectorTest::setUp public function Overrides DataCollectorBaseTest::setUp
CacheDataCollectorTest::testCacheCollectorHit public function Tests the collection of a cache hit.
CacheDataCollectorTest::testCacheCollectorMiss public function Tests the collection of a cache miss.
DataCollectorBaseTest::$exception protected property @var
DataCollectorBaseTest::$request protected property @var
DataCollectorBaseTest::$response protected property @var