ArrayAdapterTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Cache\Tests\Adapter;
  11. use Symfony\Component\Cache\Adapter\ArrayAdapter;
  12. /**
  13. * @group time-sensitive
  14. */
  15. class ArrayAdapterTest extends AdapterTestCase
  16. {
  17. protected $skippedTests = [
  18. 'testGetMetadata' => 'ArrayAdapter does not keep metadata.',
  19. 'testDeferredSaveWithoutCommit' => 'Assumes a shared cache which ArrayAdapter is not.',
  20. 'testSaveWithoutExpire' => 'Assumes a shared cache which ArrayAdapter is not.',
  21. ];
  22. public function createCachePool($defaultLifetime = 0)
  23. {
  24. return new ArrayAdapter($defaultLifetime);
  25. }
  26. public function testGetValuesHitAndMiss()
  27. {
  28. /** @var ArrayAdapter $cache */
  29. $cache = $this->createCachePool();
  30. // Hit
  31. $item = $cache->getItem('foo');
  32. $item->set('::4711');
  33. $cache->save($item);
  34. $fooItem = $cache->getItem('foo');
  35. $this->assertTrue($fooItem->isHit());
  36. $this->assertEquals('::4711', $fooItem->get());
  37. // Miss (should be present as NULL in $values)
  38. $cache->getItem('bar');
  39. $values = $cache->getValues();
  40. $this->assertCount(2, $values);
  41. $this->assertArrayHasKey('foo', $values);
  42. $this->assertSame(serialize('::4711'), $values['foo']);
  43. $this->assertArrayHasKey('bar', $values);
  44. $this->assertNull($values['bar']);
  45. }
  46. }