PredisProfileTestCase.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /*
  3. * This file is part of the Predis package.
  4. *
  5. * (c) Daniele Alessandri <suppakilla@gmail.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Predis\Profile;
  11. use PredisTestCase;
  12. /**
  13. *
  14. */
  15. abstract class PredisProfileTestCase extends PredisTestCase
  16. {
  17. /**
  18. * Returns a new instance of the tested profile.
  19. *
  20. * @param string $version Version of Redis.
  21. * @return ServerProfileInterface
  22. */
  23. protected function getProfile($version = null)
  24. {
  25. $this->markTestIncomplete("Server profile must be defined in ".get_class($this));
  26. }
  27. /**
  28. * Returns the expected version string for the tested profile.
  29. *
  30. * @return string Version string.
  31. */
  32. abstract protected function getExpectedVersion();
  33. /**
  34. * Returns the expected list of commands supported by the tested profile.
  35. *
  36. * @return array List of supported commands.
  37. */
  38. abstract protected function getExpectedCommands();
  39. /**
  40. * Returns the list of commands supported by the current
  41. * server profile.
  42. *
  43. * @param ServerProfileInterface $profile Server profile instance.
  44. * @return array
  45. */
  46. protected function getCommands(ServerProfileInterface $profile)
  47. {
  48. $commands = $profile->getSupportedCommands();
  49. return array_keys($commands);
  50. }
  51. /**
  52. * @group disconnected
  53. */
  54. public function testGetVersion()
  55. {
  56. $profile = $this->getProfile();
  57. $this->assertEquals($this->getExpectedVersion(), $profile->getVersion());
  58. }
  59. /**
  60. * @group disconnected
  61. */
  62. public function testSupportedCommands()
  63. {
  64. $profile = $this->getProfile();
  65. $expected = $this->getExpectedCommands();
  66. $commands = $this->getCommands($profile);
  67. $this->assertSame($expected, $commands);
  68. }
  69. }