MemcachedCacheTest.php 1.4 KB

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