class CacheDataCollectorTest in Devel 4.x
Same name and namespace in other branches
- 8.3 webprofiler/tests/src/Unit/DataCollector/CacheDataCollectorTest.php \Drupal\Tests\webprofiler\Unit\DataCollector\CacheDataCollectorTest
- 8 webprofiler/tests/src/Unit/DataCollector/CacheDataCollectorTest.php \Drupal\Tests\webprofiler\Unit\DataCollector\CacheDataCollectorTest
- 8.2 webprofiler/tests/src/Unit/DataCollector/CacheDataCollectorTest.php \Drupal\Tests\webprofiler\Unit\DataCollector\CacheDataCollectorTest
@coversDefaultClass \Drupal\webprofiler\DataCollector\CacheDataCollector
@group webprofiler
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, PhpUnitCompatibilityTrait, PhpUnitWarnings
- class \Drupal\Tests\webprofiler\Unit\DataCollector\DataCollectorBaseTest
- class \Drupal\Tests\webprofiler\Unit\DataCollector\CacheDataCollectorTest
- class \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\DataCollectorView 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
->createMock('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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CacheDataCollectorTest:: |
private | property | ||
CacheDataCollectorTest:: |
private | property | ||
CacheDataCollectorTest:: |
public | function |
Overrides DataCollectorBaseTest:: |
|
CacheDataCollectorTest:: |
public | function | Tests the collection of a cache hit. | |
CacheDataCollectorTest:: |
public | function | Tests the collection of a cache miss. | |
DataCollectorBaseTest:: |
protected | property | @var | |
DataCollectorBaseTest:: |
protected | property | @var | |
DataCollectorBaseTest:: |
protected | property | @var | |
PhpUnitWarnings:: |
private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |
PhpUnitWarnings:: |
public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
public static | function |