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_Memcache_Test.php 1.6 KiB

3 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/env php
  2. <?php
  3. /**
  4. * PhpUnderControl_PhalApiCacheMemcache_Test
  5. *
  6. * 针对 ../../PhalApi/Cache/Memcache.php PhalApi_Cache_Memcache 类的PHPUnit单元测试
  7. *
  8. * @author: dogstar 20150507
  9. */
  10. require_once dirname(__FILE__) . '/../test_env.php';
  11. if (!class_exists('PhalApi_Cache_Memcache')) {
  12. require dirname(__FILE__) . '/../../PhalApi/Cache/Memcache.php';
  13. }
  14. class PhpUnderControl_PhalApiCacheMemcache_Test extends PHPUnit_Framework_TestCase
  15. {
  16. public $phalApiCacheMemcache;
  17. protected function setUp()
  18. {
  19. parent::setUp();
  20. $config = array('host' => '127.0.0.1', 'port' => '11211');
  21. $this->phalApiCacheMemcache = new PhalApi_Cache_Memcache($config);
  22. }
  23. protected function tearDown()
  24. {
  25. }
  26. /**
  27. * @group testSet
  28. */
  29. public function testSet()
  30. {
  31. $key = 'key-2015-05-07';
  32. $value = 'phalapi';
  33. $expire = 60;
  34. $this->phalApiCacheMemcache->set($key, $value, $expire);
  35. $this->assertEquals('phalapi', $this->phalApiCacheMemcache->get($key));
  36. }
  37. /**
  38. * @group testGet
  39. */
  40. public function testGet()
  41. {
  42. $key = 'no-this-key';
  43. $rs = $this->phalApiCacheMemcache->get($key);
  44. $this->assertSame(NULL, $rs);
  45. }
  46. /**
  47. * @group testDelete
  48. */
  49. public function testDelete()
  50. {
  51. $key = 'key-2015-05-07';
  52. $this->assertNotNull($this->phalApiCacheMemcache->get($key));
  53. $this->phalApiCacheMemcache->delete($key);
  54. $this->assertNull($this->phalApiCacheMemcache->get($key));
  55. }
  56. }