ServerVersionTestCase.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 \PHPUnit_Framework_TestCase as StandardTestCase;
  12. /**
  13. *
  14. */
  15. abstract class ServerVersionTestCase extends StandardTestCase
  16. {
  17. /**
  18. * Returns a new instance of the tested profile.
  19. *
  20. * @return ServerProfileInterface
  21. */
  22. protected abstract function getProfileInstance();
  23. /**
  24. * Returns the expected version string for the tested profile.
  25. *
  26. * @return string Version string.
  27. */
  28. protected abstract function getExpectedVersion();
  29. /**
  30. * Returns the expected list of commands supported by the tested profile.
  31. *
  32. * @return array List of supported commands.
  33. */
  34. protected abstract function getExpectedCommands();
  35. /**
  36. * Returns the list of commands supported by the current
  37. * server profile.
  38. *
  39. * @param ServerProfileInterface $profile Server profile instance.
  40. * @return array
  41. */
  42. protected function getCommands(ServerProfileInterface $profile)
  43. {
  44. $commands = $profile->getSupportedCommands();
  45. return array_keys($commands);
  46. }
  47. /**
  48. * @group disconnected
  49. */
  50. public function testGetVersion()
  51. {
  52. $profile = $this->getProfileInstance();
  53. $this->assertEquals($this->getExpectedVersion(), $profile->getVersion());
  54. }
  55. /**
  56. * @group disconnected
  57. */
  58. public function testSupportedCommands()
  59. {
  60. $profile = $this->getProfileInstance();
  61. $expected = $this->getExpectedCommands();
  62. $commands = $this->getCommands($profile);
  63. $this->assertSame($expected, $commands);
  64. }
  65. }