NullCacheTest.php 2.2 KB

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