NullCacheTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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\Simple;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Cache\Simple\NullCache;
  13. /**
  14. * @group time-sensitive
  15. * @group legacy
  16. */
  17. class NullCacheTest extends TestCase
  18. {
  19. public function createCachePool()
  20. {
  21. return new NullCache();
  22. }
  23. public function testGetItem()
  24. {
  25. $cache = $this->createCachePool();
  26. $this->assertNull($cache->get('key'));
  27. }
  28. public function testHas()
  29. {
  30. $this->assertFalse($this->createCachePool()->has('key'));
  31. }
  32. public function testGetMultiple()
  33. {
  34. $cache = $this->createCachePool();
  35. $keys = ['foo', 'bar', 'baz', 'biz'];
  36. $default = new \stdClass();
  37. $items = $cache->getMultiple($keys, $default);
  38. $count = 0;
  39. foreach ($items as $key => $item) {
  40. $this->assertContains($key, $keys, 'Cache key can not change.');
  41. $this->assertSame($default, $item);
  42. // Remove $key for $keys
  43. foreach ($keys as $k => $v) {
  44. if ($v === $key) {
  45. unset($keys[$k]);
  46. }
  47. }
  48. ++$count;
  49. }
  50. $this->assertSame(4, $count);
  51. }
  52. public function testClear()
  53. {
  54. $this->assertTrue($this->createCachePool()->clear());
  55. }
  56. public function testDelete()
  57. {
  58. $this->assertTrue($this->createCachePool()->delete('key'));
  59. }
  60. public function testDeleteMultiple()
  61. {
  62. $this->assertTrue($this->createCachePool()->deleteMultiple(['key', 'foo', 'bar']));
  63. }
  64. public function testSet()
  65. {
  66. $cache = $this->createCachePool();
  67. $this->assertFalse($cache->set('key', 'val'));
  68. $this->assertNull($cache->get('key'));
  69. }
  70. public function testSetMultiple()
  71. {
  72. $cache = $this->createCachePool();
  73. $this->assertFalse($cache->setMultiple(['key' => 'val']));
  74. $this->assertNull($cache->get('key'));
  75. }
  76. }