class YamlCacheCollectorTest

Same name and namespace in other branches
  1. main core/tests/Drupal/Tests/Core/Utility/YamlCacheCollectorTest.php \Drupal\Tests\Core\Utility\YamlCacheCollectorTest

Tests Drupal\Core\Cache\CacheCollector.

Attributes

#[CoversClass(CacheCollector::class)] #[Group('Cache')]

Hierarchy

Expanded class hierarchy of YamlCacheCollectorTest

File

core/tests/Drupal/Tests/Core/Utility/YamlCacheCollectorTest.php, line 22

Namespace

Drupal\Tests\Core\Utility
View source
class YamlCacheCollectorTest extends UnitTestCase {
  
  /**
   * The cache backend that should be used.
   */
  protected CacheBackendInterface $cacheBackend;
  
  /**
   * The lock backend that should be used.
   */
  protected LockBackendInterface $lock;
  
  /**
   * The time instance that should be used.
   */
  protected TimeInterface $time;
  
  /**
   * The cache id used for the test.
   *
   * @var string
   */
  protected $cid;
  
  /**
   * Cache collector implementation to test.
   *
   * @var \Drupal\Tests\Core\Cache\CacheCollectorHelper
   */
  protected $collector;
  
  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $this->time = new Time();
    $this->cacheBackend = new MemoryBackend($this->time);
    $this->lock = new NullLockBackend();
    $this->cid = 'test';
    $this->collector = new YamlCacheCollector($this->cid, $this->cacheBackend, $this->lock, $this->time);
  }
  
  /**
   * Tests the ::updateCache() function.
   */
  public function testUpdateCache() : void {
    $this->cacheBackend
      ->set('key', [
      '/foo/bar/foo_bar.txt' => [
        'data' => [
          TRUE,
        ],
        'mtime' => 12345,
      ],
    ]);
    $this->collector
      ->set('/foo/bar/foo_bar.txt', [
      'data' => [
        'hello',
      ],
      'mtime' => 12345,
    ]);
    $this->collector
      ->updateCache();
    $this->assertSame($this->collector
      ->get('/foo/bar/foo_bar.txt'), []);
    $cached = $this->cacheBackend
      ->get('key');
    $this->assertArrayNotHasKey('foo_bar.txt', $cached->data);
  }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title Overrides
DrupalTestCaseTrait::$root protected property The Drupal root directory.
DrupalTestCaseTrait::checkErrorHandlerOnTearDown public function Checks the test error handler after test execution. 1
DrupalTestCaseTrait::getDrupalRoot Deprecated protected static function Returns the Drupal root directory. 1
DrupalTestCaseTrait::setDebugDumpHandler public static function Registers the dumper CLI handler when the DebugDump extension is enabled.
DrupalTestCaseTrait::setUpRoot final protected function Ensure that the $root property is set initially.
ExpectDeprecationTrait::expectDeprecation Deprecated public function Adds an expected deprecation.
ExpectDeprecationTrait::regularExpressionForFormatDescription private function
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers.
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::setupMockIterator protected function Set up a traversable class mock to return specific items when iterated.
YamlCacheCollectorTest::$cacheBackend protected property The cache backend that should be used.
YamlCacheCollectorTest::$cid protected property The cache id used for the test.
YamlCacheCollectorTest::$collector protected property Cache collector implementation to test.
YamlCacheCollectorTest::$lock protected property The lock backend that should be used.
YamlCacheCollectorTest::$time protected property The time instance that should be used.
YamlCacheCollectorTest::setUp protected function Overrides UnitTestCase::setUp
YamlCacheCollectorTest::testUpdateCache public function Tests the ::updateCache() function.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.