MemcacheCacheTest.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace Doctrine\Tests\Common\Cache;
  3. use Doctrine\Common\Cache\MemcacheCache;
  4. use Memcache;
  5. /**
  6. * @requires extension memcache
  7. */
  8. class MemcacheCacheTest extends CacheTest
  9. {
  10. private $memcache;
  11. protected function setUp()
  12. {
  13. $this->memcache = new Memcache();
  14. if (@$this->memcache->connect('localhost', 11211) === false) {
  15. unset($this->memcache);
  16. $this->markTestSkipped('Cannot connect to Memcache.');
  17. }
  18. }
  19. protected function tearDown()
  20. {
  21. if ($this->memcache instanceof Memcache) {
  22. $this->memcache->flush();
  23. }
  24. }
  25. /**
  26. * {@inheritdoc}
  27. *
  28. * Memcache does not support " " and null byte as key so we remove them from the tests.
  29. */
  30. public function provideCacheIds()
  31. {
  32. $ids = parent::provideCacheIds();
  33. unset($ids[21], $ids[22]);
  34. return $ids;
  35. }
  36. public function testGetMemcacheReturnsInstanceOfMemcache()
  37. {
  38. $this->assertInstanceOf('Memcache', $this->_getCacheDriver()->getMemcache());
  39. }
  40. /**
  41. * {@inheritDoc}
  42. */
  43. protected function _getCacheDriver()
  44. {
  45. $driver = new MemcacheCache();
  46. $driver->setMemcache($this->memcache);
  47. return $driver;
  48. }
  49. }