PredisProfileTestCase.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. * @return ServerProfileInterface
  21. */
  22. protected function getProfile($version = null)
  23. {
  24. $this->markTestIncomplete("Server profile must be defined in ".get_class($this));
  25. }
  26. /**
  27. * Returns the expected version string for the tested profile.
  28. *
  29. * @return string Version string.
  30. */
  31. abstract protected function getExpectedVersion();
  32. /**
  33. * Returns the expected list of commands supported by the tested profile.
  34. *
  35. * @return array List of supported commands.
  36. */
  37. abstract protected function getExpectedCommands();
  38. /**
  39. * Returns the list of commands supported by the current
  40. * server profile.
  41. *
  42. * @param ServerProfileInterface $profile Server profile instance.
  43. * @return array
  44. */
  45. protected function getCommands(ServerProfileInterface $profile)
  46. {
  47. $commands = $profile->getSupportedCommands();
  48. return array_keys($commands);
  49. }
  50. /**
  51. * @group disconnected
  52. */
  53. public function testGetVersion()
  54. {
  55. $profile = $this->getProfile();
  56. $this->assertEquals($this->getExpectedVersion(), $profile->getVersion());
  57. }
  58. /**
  59. * @group disconnected
  60. */
  61. public function testSupportedCommands()
  62. {
  63. $profile = $this->getProfile();
  64. $expected = $this->getExpectedCommands();
  65. $commands = $this->getCommands($profile);
  66. $this->assertSame($expected, $commands);
  67. }
  68. }