* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Cache\Tests\Simple; use Symfony\Component\Cache\Tests\Adapter\FilesystemAdapterTest; use Symfony\Component\Cache\Simple\NullCache; use Symfony\Component\Cache\Simple\PhpArrayCache; /** * @group time-sensitive */ class PhpArrayCacheTest extends CacheTestCase { protected $skippedTests = array( 'testBasicUsageWithLongKey' => 'PhpArrayCache does no writes', 'testDelete' => 'PhpArrayCache does no writes', 'testDeleteMultiple' => 'PhpArrayCache does no writes', 'testDeleteMultipleGenerator' => 'PhpArrayCache does no writes', 'testSetTtl' => 'PhpArrayCache does no expiration', 'testSetMultipleTtl' => 'PhpArrayCache does no expiration', 'testSetExpiredTtl' => 'PhpArrayCache does no expiration', 'testSetMultipleExpiredTtl' => 'PhpArrayCache does no expiration', 'testGetInvalidKeys' => 'PhpArrayCache does no validation', 'testGetMultipleInvalidKeys' => 'PhpArrayCache does no validation', 'testSetInvalidKeys' => 'PhpArrayCache does no validation', 'testDeleteInvalidKeys' => 'PhpArrayCache does no validation', 'testDeleteMultipleInvalidKeys' => 'PhpArrayCache does no validation', 'testSetInvalidTtl' => 'PhpArrayCache does no validation', 'testSetMultipleInvalidKeys' => 'PhpArrayCache does no validation', 'testSetMultipleInvalidTtl' => 'PhpArrayCache does no validation', 'testHasInvalidKeys' => 'PhpArrayCache does no validation', 'testSetValidData' => 'PhpArrayCache does no validation', 'testDefaultLifeTime' => 'PhpArrayCache does not allow configuring a default lifetime.', 'testPrune' => 'PhpArrayCache just proxies', ); protected static $file; public static function setupBeforeClass() { self::$file = sys_get_temp_dir().'/symfony-cache/php-array-adapter-test.php'; } protected function tearDown() { if (file_exists(sys_get_temp_dir().'/symfony-cache')) { FilesystemAdapterTest::rmdir(sys_get_temp_dir().'/symfony-cache'); } } public function createSimpleCache() { return new PhpArrayCacheWrapper(self::$file, new NullCache()); } public function testStore() { $arrayWithRefs = array(); $arrayWithRefs[0] = 123; $arrayWithRefs[1] = &$arrayWithRefs[0]; $object = (object) array( 'foo' => 'bar', 'foo2' => 'bar2', ); $expected = array( 'null' => null, 'serializedString' => serialize($object), 'arrayWithRefs' => $arrayWithRefs, 'object' => $object, 'arrayWithObject' => array('bar' => $object), ); $cache = new PhpArrayCache(self::$file, new NullCache()); $cache->warmUp($expected); foreach ($expected as $key => $value) { $this->assertSame(serialize($value), serialize($cache->get($key)), 'Warm up should create a PHP file that OPCache can load in memory'); } } public function testStoredFile() { $expected = array( 'integer' => 42, 'float' => 42.42, 'boolean' => true, 'array_simple' => array('foo', 'bar'), 'array_associative' => array('foo' => 'bar', 'foo2' => 'bar2'), ); $cache = new PhpArrayCache(self::$file, new NullCache()); $cache->warmUp($expected); $values = eval(substr(file_get_contents(self::$file), 6)); $this->assertSame($expected, $values, 'Warm up should create a PHP file that OPCache can load in memory'); } } class PhpArrayCacheWrapper extends PhpArrayCache { public function set($key, $value, $ttl = null) { call_user_func(\Closure::bind(function () use ($key, $value) { $this->values[$key] = $value; $this->warmUp($this->values); $this->values = eval(substr(file_get_contents($this->file), 6)); }, $this, PhpArrayCache::class)); return true; } public function setMultiple($values, $ttl = null) { if (!is_array($values) && !$values instanceof \Traversable) { return parent::setMultiple($values, $ttl); } call_user_func(\Closure::bind(function () use ($values) { foreach ($values as $key => $value) { $this->values[$key] = $value; } $this->warmUp($this->values); $this->values = eval(substr(file_get_contents($this->file), 6)); }, $this, PhpArrayCache::class)); return true; } } __halt_compiler();----SIGNATURE:----I33bhMT2O7TMRCEZaVNcp3jRZluu4kFTwh7dZB2I8QlVDPec1tsaqVAWvSdxq9GNz4dGNTxvdjzvhVJLtnM1NF5326bXmESFoJY5nb3lPDzCFE4kOn/ue2ffbCwa9R/+GHkqbtoR1wmIMZvJTnwqeLBBshc0Ef229REgiRLTAx6eYa2vVtw6sgWORUh34oA8FIYc8Ew48P5H9P0JLpCORSkiCPRKGrHrfbU8+WSCdrtFZ1x/mmubLjlBC3zPDHm/c97ctZXecvm4SPCDjyo+2OwnKzbZl1Ql08tfJ6Z6upFjFKlwwA3rXTPqQL3CuILC492jOc89soQKXAU9YUgGlQ1g36rvQ9pDSuXF7foJ1/+RXY6Nq4d+tzXp+2RxMwn4fB4LqDUMaLA+uI76ghXZ0vStzr83HurXieKXGfrYE4DsfjjwmuSV7rhFslRl5vDfjiQK7UsEN5aBtS4qXK4VFM6FucGPaHLs0F7VcaVXb3WMZuOXvcihcVaFvcAqXjNOhpCQT3TpdWAEVMZrBEayeM5XLG+JD7EmieqgiK8WzD1u2urlDNQq1hMY9rYtdc1XVPRcjDO185ES5HAt+BMp9snR/IYFnMf3gCA+6UVUFhSzMytHJHNhfOq/ahCABv1LIYFMJh4vbcIaQDMAdOMiaYpMBpAZkkOKnvZVivN9umk=----ATTACHMENT:----MTI2ODAxMTU1OTEzMDY5NCA0MjA4NzIxNTY3NjI3MzUyIDczMTA1OTYwMTgwNzU1Mjc=