You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.2 KiB

  1. <?php
  2. /*
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage UnitTests
  7. * @since 2011-10-14
  8. *
  9. * Unit tests for CacheKey class
  10. */
  11. /**
  12. * @TODO: CacheKey->getExpire() method never used
  13. */
  14. require_once dirname(__FILE__) . '/../../cache/Cache.php';
  15. require_once dirname(__FILE__) . '/../../cache/CacheKey.php';
  16. class CacheKeyTest extends PHPUnit_Framework_TestCase
  17. {
  18. private $cache;
  19. public function testConstructor()
  20. {
  21. $mock = $this->getMock('Cache');
  22. $cache = new CacheKey($mock, 'anything', array('one', 'two', 'three'),200);
  23. $this->assertAttributeEquals('anything_one|two|three', 'key', $cache);
  24. }
  25. public function testExpire()
  26. {
  27. $this->cache = new CacheKey($this->getMock('Cache'), 'key');
  28. $this->assertAttributeEquals(0, 'expire', $this->cache);
  29. $this->cache->setExpire(20);
  30. $this->assertAttributeEquals(20, 'expire', $this->cache);
  31. }
  32. public function testGetExpire()
  33. {
  34. $this->cache = new CacheKey(null, 'key');
  35. $this->cache->setExpire(100);
  36. $getExpireMethod = new ReflectionMethod('CacheKey', 'getExpire');
  37. $getExpireMethod->setAccessible(TRUE);
  38. $this->assertSame(100, $getExpireMethod->invoke($this->cache));
  39. }
  40. public function testGetSet()
  41. {
  42. $mockCacher = $this->getMock('Cache');
  43. $mockCacher->expects($this->any())
  44. ->method('set')
  45. ->with('any', 'some', 0);
  46. $mockCacher->expects($this->any())
  47. ->method('get')
  48. ->with('any')
  49. ->will($this->returnValue('some'));
  50. $this->cache = new CacheKey($mockCacher, 'any');
  51. $this->cache->set('some');
  52. $this->assertSame('some', $this->cache->get());
  53. }
  54. public function testDel()
  55. {
  56. $mockCacher = $this->getMock('Cacher', array('del'));
  57. $mockCacher->expects($this->any())
  58. ->method('del')
  59. ->with('some')
  60. ->will($this->returnValue(true));
  61. $cache = new CacheKey($mockCacher, 'some');
  62. $this->assertTrue($cache->del());
  63. }
  64. }