Ejemplo n.º 1
0
 /**
  * Tests setting and invalidating
  *
  * @dataProvider providerTestInvalidCharacters
  */
 public function testCacheCollector($cid, $key, $value)
 {
     $collector = new CacheCollectorHelper($cid, $this->container->get('cache.default'), $this->container->get('lock'));
     $this->assertNull($collector->get($key));
     $collector->set($key, $value);
     $this->assertEquals($value, $collector->get($key));
     $collector->destruct();
     // @todo Shouldn't this be empty after destruction?
     $this->assertEquals($value, $collector->get($key));
 }
Ejemplo n.º 2
0
 /**
  * Tests updating the cache when there is a conflict after cache invalidation.
  */
 public function testUpdateCacheInvalidatedConflict()
 {
     $key = $this->randomMachineName();
     $value = $this->randomMachineName();
     $cache = (object) array('data' => array($key => $value), 'created' => (int) $_SERVER['REQUEST_TIME']);
     $this->cacheBackend->expects($this->at(0))->method('get')->with($this->cid)->will($this->returnValue($cache));
     $this->cacheBackend->expects($this->at(1))->method('invalidate')->with($this->cid);
     $this->collector->set($key, 'new value');
     // Set up mock objects for the expected calls, first a lock acquire, then
     // cache get to look for conflicting cache entries, which does find
     // and then it deletes the cache and aborts.
     $this->lock->expects($this->once())->method('acquire')->with($this->cid . ':Drupal\\Core\\Cache\\CacheCollector')->will($this->returnValue(TRUE));
     $cache = (object) array('data' => array($key => $value), 'created' => (int) $_SERVER['REQUEST_TIME'] + 1);
     $this->cacheBackend->expects($this->at(0))->method('get')->with($this->cid)->will($this->returnValue($cache));
     $this->cacheBackend->expects($this->once())->method('delete')->with($this->cid);
     $this->lock->expects($this->once())->method('release')->with($this->cid . ':Drupal\\Core\\Cache\\CacheCollector');
     // Destruct the object to trigger the update data process.
     $this->collector->destruct();
 }