FactoryTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. use Predis\Command\Processor\ProcessorChain;
  13. /**
  14. *
  15. */
  16. class FactoryTest extends PredisTestCase
  17. {
  18. const DEFAULT_PROFILE_VERSION = '2.8';
  19. const DEVELOPMENT_PROFILE_VERSION = '3.0';
  20. /**
  21. * @group disconnected
  22. */
  23. public function testGetVersion()
  24. {
  25. $profile = Factory::get('2.0');
  26. $this->assertInstanceOf('Predis\Profile\ProfileInterface', $profile);
  27. $this->assertEquals('2.0', $profile->getVersion());
  28. }
  29. /**
  30. * @group disconnected
  31. */
  32. public function testGetDefault()
  33. {
  34. $profile1 = Factory::get(self::DEFAULT_PROFILE_VERSION);
  35. $profile2 = Factory::get('default');
  36. $profile3 = Factory::getDefault();
  37. $this->assertInstanceOf('Predis\Profile\ProfileInterface', $profile1);
  38. $this->assertInstanceOf('Predis\Profile\ProfileInterface', $profile2);
  39. $this->assertInstanceOf('Predis\Profile\ProfileInterface', $profile3);
  40. $this->assertEquals($profile1->getVersion(), $profile2->getVersion());
  41. $this->assertEquals($profile2->getVersion(), $profile3->getVersion());
  42. }
  43. /**
  44. * @group disconnected
  45. */
  46. public function testGetDevelopment()
  47. {
  48. $profile1 = Factory::get('dev');
  49. $profile2 = Factory::getDevelopment();
  50. $this->assertInstanceOf('Predis\Profile\ProfileInterface', $profile1);
  51. $this->assertInstanceOf('Predis\Profile\ProfileInterface', $profile2);
  52. $this->assertEquals(self::DEVELOPMENT_PROFILE_VERSION, $profile2->getVersion());
  53. }
  54. /**
  55. * @group disconnected
  56. * @expectedException Predis\ClientException
  57. * @expectedExceptionMessage Unknown server profile: 1.0
  58. */
  59. public function testGetUndefinedProfile()
  60. {
  61. Factory::get('1.0');
  62. }
  63. /**
  64. * @group disconnected
  65. */
  66. public function testDefineProfile()
  67. {
  68. $profileClass = get_class($this->getMock('Predis\Profile\ProfileInterface'));
  69. Factory::define('mock', $profileClass);
  70. $this->assertInstanceOf($profileClass, Factory::get('mock'));
  71. }
  72. /**
  73. * @group disconnected
  74. * @expectedException InvalidArgumentException
  75. * @expectedExceptionMessage Cannot register 'stdClass' as it is not a valid profile class
  76. */
  77. public function testDefineInvalidProfile()
  78. {
  79. Factory::define('bogus', 'stdClass');
  80. }
  81. }