FactoryTest.php 2.6 KB

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