ArrayAdapterTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. 'testDeferredSaveWithoutCommit' => 'Assumes a shared cache which ArrayAdapter is not.',
  19. 'testSaveWithoutExpire' => 'Assumes a shared cache which ArrayAdapter is not.',
  20. ];
  21. public function createCachePool($defaultLifetime = 0)
  22. {
  23. return new ArrayAdapter($defaultLifetime);
  24. }
  25. public function testGetValuesHitAndMiss()
  26. {
  27. /** @var ArrayAdapter $cache */
  28. $cache = $this->createCachePool();
  29. // Hit
  30. $item = $cache->getItem('foo');
  31. $item->set('4711');
  32. $cache->save($item);
  33. $fooItem = $cache->getItem('foo');
  34. $this->assertTrue($fooItem->isHit());
  35. $this->assertEquals('4711', $fooItem->get());
  36. // Miss (should be present as NULL in $values)
  37. $cache->getItem('bar');
  38. $values = $cache->getValues();
  39. $this->assertCount(2, $values);
  40. $this->assertArrayHasKey('foo', $values);
  41. $this->assertSame(serialize('4711'), $values['foo']);
  42. $this->assertArrayHasKey('bar', $values);
  43. $this->assertNull($values['bar']);
  44. }
  45. }