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.

PhalApi_Cache_File_Test.php 2.0 KiB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * PhpUnderControl_PhalApiCacheFile_Test
  4. *
  5. * 针对 ../../PhalApi/Cache/File.php PhalApi_Cache_File 类的PHPUnit单元测试
  6. *
  7. * @author: dogstar 20150226
  8. */
  9. require_once dirname(__FILE__) . '/../test_env.php';
  10. if (!class_exists('PhalApi_Cache_File')) {
  11. require dirname(__FILE__) . '/../../PhalApi/Cache/File.php';
  12. }
  13. class PhpUnderControl_PhalApiCacheFile_Test extends PHPUnit_Framework_TestCase
  14. {
  15. public $phalApiCacheFile;
  16. protected function setUp()
  17. {
  18. parent::setUp();
  19. @unlink(dirname(__FILE__) . '/cache');
  20. $config['path'] = dirname(__FILE__);
  21. $this->phalApiCacheFile = new PhalApi_Cache_File($config);
  22. }
  23. protected function tearDown()
  24. {
  25. }
  26. /**
  27. * @group testSet
  28. */
  29. public function testSet()
  30. {
  31. $key = 'aYearKey';
  32. $value = 2015;
  33. $expire = '200';
  34. $rs = $this->phalApiCacheFile->set($key, $value, $expire);
  35. }
  36. /**
  37. * @group testGet
  38. * @depends testSet
  39. */
  40. public function testGet()
  41. {
  42. $key = 'aYearKey';
  43. $rs = $this->phalApiCacheFile->get($key);
  44. $this->assertSame(2015, $rs);
  45. }
  46. /**
  47. * @group testDelete
  48. * @depends testSet
  49. */
  50. public function testDelete()
  51. {
  52. $key = 'aYearKey';
  53. $this->phalApiCacheFile->delete($key);
  54. $rs = $this->phalApiCacheFile->get($key);
  55. $this->assertSame(NULL, $rs);
  56. }
  57. public function testGetAfterSet()
  58. {
  59. $key = 'anotherKey';
  60. $value = array('name' => 'dogstar');
  61. $this->phalApiCacheFile->set($key, $value);
  62. $this->assertSame($value, $this->phalApiCacheFile->get($key));
  63. }
  64. public function testExpire()
  65. {
  66. $key = 'tmpKey';
  67. $value = 'somethinghere~';
  68. $expire = 2;
  69. $this->phalApiCacheFile->set($key, $value, $expire);
  70. $this->assertSame($value, $this->phalApiCacheFile->get($key));
  71. sleep(3);
  72. $this->assertSame(NULL, $this->phalApiCacheFile->get($key));
  73. }
  74. }