diff --git a/core/tests/Drupal/Tests/Core/PhpStorage/CacheStorageTest.php b/core/tests/Drupal/Tests/Core/PhpStorage/CacheStorageTest.php index ff1caed..26a5adf 100644 --- a/core/tests/Drupal/Tests/Core/PhpStorage/CacheStorageTest.php +++ b/core/tests/Drupal/Tests/Core/PhpStorage/CacheStorageTest.php @@ -7,7 +7,6 @@ namespace Drupal\Tests\Core\PhpStorage; -use Drupal\Component\PhpStorage\PhpStorageInterface; use Drupal\Core\Cache\MemoryBackend; use Drupal\Core\PhpStorage\CacheStorage; use Drupal\Tests\Component\PhpStorage\PhpStorageTestBase; @@ -20,6 +19,13 @@ class CacheStorageTest extends PhpStorageTestBase { /** + * The contents of the cache backend. + * + * @var array + */ + protected $cache; + + /** * Tests basic load/save/delete operations. * * @covers ::load @@ -39,16 +45,40 @@ public function testCRUD() { $this->assertCRUD($storage); } - /** - * {@inheritdoc} - */ - protected function additionalAssertCRUD(PhpStorageInterface $php, $name) { - $this->assertTrue(isset(opcache_get_status(TRUE)['scripts']["phar://$name"]['hits'])); - if (ini_get('opcache.enable_cli')) { - $this->assertEquals(opcache_get_status(TRUE)['scripts']["phar://$name"]['hits'], 0); - $php->load($name); - $this->assertEquals(opcache_get_status(TRUE)['scripts']["phar://$name"]['hits'], 1); - } + public function testCache() { + $cache_backend = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); + $cache_backend->expects($this->once()) + ->method('setMultiple') + ->willReturnCallback(function ($data) { + $this->cache = $data; + }); + // mtime wil be retrieved on both loads. If opcache.enable_cli is on then + // the file itself is loaded only once. + $cache_backend->expects($this->exactly(4 - ini_get('opcache.enable_cli'))) + ->method('get') + ->willReturnCallback(function ($cid) { + return (object) $this->cache[$cid]; + }); + $secret = $this->randomMachineName(); + $storage = new CacheStorage([ + 'secret' => $secret, + 'cache_backend_factory' => function () use ($cache_backend) { + return $cache_backend; + }, + 'bin' => 'test' + ]); + $name = $this->randomMachineName() . '/' . $this->randomMachineName() . '.php'; + + // Find a global that doesn't exist. + do { + $random = mt_rand(10000, 100000); + } while (isset($GLOBALS[$random])); + + // Write out a PHP file and ensure it's successfully loaded. + $code = "save($name, $code); + $storage->load($name); + $storage->load($name); } }