1
0

CappedMemoryCacheTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Robin Appelman
  6. * @copyright 2016 Robin Appelman icewind@owncloud.com
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. namespace Test\Cache;
  23. /**
  24. * Class CappedMemoryCacheTest
  25. *
  26. * @package Test\Cache
  27. */
  28. class CappedMemoryCacheTest extends TestCache {
  29. public function setUp() {
  30. parent::setUp();
  31. $this->instance = new \OC\Cache\CappedMemoryCache();
  32. }
  33. public function testSetOverCap() {
  34. $instance = new \OC\Cache\CappedMemoryCache(3);
  35. $instance->set('1', 'a');
  36. $instance->set('2', 'b');
  37. $instance->set('3', 'c');
  38. $instance->set('4', 'd');
  39. $instance->set('5', 'e');
  40. $this->assertFalse($instance->hasKey('1'));
  41. $this->assertFalse($instance->hasKey('2'));
  42. $this->assertTrue($instance->hasKey('3'));
  43. $this->assertTrue($instance->hasKey('4'));
  44. $this->assertTrue($instance->hasKey('5'));
  45. }
  46. function testClear() {
  47. $value = 'ipsum lorum';
  48. $this->instance->set('1_value1', $value);
  49. $this->instance->set('1_value2', $value);
  50. $this->instance->set('2_value1', $value);
  51. $this->instance->set('3_value1', $value);
  52. $this->assertTrue($this->instance->clear());
  53. $this->assertFalse($this->instance->hasKey('1_value1'));
  54. $this->assertFalse($this->instance->hasKey('1_value2'));
  55. $this->assertFalse($this->instance->hasKey('2_value1'));
  56. $this->assertFalse($this->instance->hasKey('3_value1'));
  57. }
  58. function testIndirectSet() {
  59. $this->instance->set('array', []);
  60. $this->instance['array'][] = 'foo';
  61. $this->assertEquals(['foo'], $this->instance->get('array'));
  62. $this->instance['array']['bar'] = 'qwerty';
  63. $this->assertEquals(['foo', 'bar' => 'qwerty'], $this->instance->get('array'));
  64. }
  65. }