PredisCacheTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace Doctrine\Tests\Common\Cache;
  3. use Doctrine\Common\Cache\Cache;
  4. use Doctrine\Common\Cache\PredisCache;
  5. use Predis\Client;
  6. use Predis\Connection\ConnectionException;
  7. class PredisCacheTest extends CacheTest
  8. {
  9. private $client;
  10. public function setUp()
  11. {
  12. if (!class_exists('Predis\Client')) {
  13. $this->markTestSkipped('Predis\Client is missing. Make sure to "composer install" to have all dev dependencies.');
  14. }
  15. $this->client = new Client();
  16. try {
  17. $this->client->connect();
  18. } catch (ConnectionException $e) {
  19. $this->markTestSkipped('The ' . __CLASS__ .' requires the use of redis');
  20. }
  21. }
  22. public function testHitMissesStatsAreProvided()
  23. {
  24. $cache = $this->_getCacheDriver();
  25. $stats = $cache->getStats();
  26. $this->assertNotNull($stats[Cache::STATS_HITS]);
  27. $this->assertNotNull($stats[Cache::STATS_MISSES]);
  28. }
  29. /**
  30. * @return PredisCache
  31. */
  32. protected function _getCacheDriver()
  33. {
  34. return new PredisCache($this->client);
  35. }
  36. /**
  37. * {@inheritDoc}
  38. *
  39. * @dataProvider provideDataToCache
  40. */
  41. public function testSetContainsFetchDelete($value)
  42. {
  43. if (array() === $value) {
  44. $this->markTestIncomplete(
  45. 'Predis currently doesn\'t support saving empty array values. '
  46. . 'See https://github.com/nrk/predis/issues/241'
  47. );
  48. }
  49. parent::testSetContainsFetchDelete($value);
  50. }
  51. /**
  52. * {@inheritDoc}
  53. *
  54. * @dataProvider provideDataToCache
  55. */
  56. public function testUpdateExistingEntry($value)
  57. {
  58. if (array() === $value) {
  59. $this->markTestIncomplete(
  60. 'Predis currently doesn\'t support saving empty array values. '
  61. . 'See https://github.com/nrk/predis/issues/241'
  62. );
  63. }
  64. parent::testUpdateExistingEntry($value);
  65. }
  66. }