2
0

FactoryTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * @package Zend_Cache
  4. * @subpackage UnitTests
  5. */
  6. /**
  7. * Zend_Cache
  8. */
  9. require_once 'Zend/Cache.php';
  10. /**
  11. * PHPUnit test case
  12. */
  13. require_once 'PHPUnit/Framework/TestCase.php';
  14. require_once 'Zend/Cache/Backend/File.php';
  15. class Zend_Cache_Backend_FooBarTest extends Zend_Cache_Backend_File { }
  16. class FooBarTestBackend extends Zend_Cache_Backend_File { }
  17. require_once 'Zend/Cache/Core.php';
  18. class Zend_Cache_Frontend_FooBarTest extends Zend_Cache_Core { }
  19. class FooBarTestFrontend extends Zend_Cache_Core { }
  20. /**
  21. * @package Zend_Cache
  22. * @subpackage UnitTests
  23. */
  24. class Zend_Cache_FactoryTest extends PHPUnit_Framework_TestCase
  25. {
  26. public function setUp()
  27. {
  28. }
  29. public function tearDown()
  30. {
  31. }
  32. public function testFactoryCorrectCall()
  33. {
  34. $generated_frontend = Zend_Cache::factory('Core', 'File');
  35. $this->assertEquals('Zend_Cache_Core', get_class($generated_frontend));
  36. }
  37. public function testFactoryCorrectCallWithCustomBackend()
  38. {
  39. $generated_frontend = Zend_Cache::factory('Core', 'FooBarTest', array(), array(), false, false, true);
  40. $this->assertEquals('Zend_Cache_Core', get_class($generated_frontend));
  41. }
  42. public function testFactoryCorrectCallWithCustomBackend2()
  43. {
  44. $generated_frontend = Zend_Cache::factory('Core', 'FooBarTestBackend', array(), array(), false, true, true);
  45. $this->assertEquals('Zend_Cache_Core', get_class($generated_frontend));
  46. }
  47. public function testFactoryCorrectCallWithCustomFrontend()
  48. {
  49. $generated_frontend = Zend_Cache::factory('FooBarTest', 'File', array(), array(), false, false, true);
  50. $this->assertEquals('Zend_Cache_Frontend_FooBarTest', get_class($generated_frontend));
  51. }
  52. public function testFactoryCorrectCallWithCustomFrontend2()
  53. {
  54. $generated_frontend = Zend_Cache::factory('FooBarTestFrontend', 'File', array(), array(), true, false, true);
  55. $this->assertEquals('FooBarTestFrontend', get_class($generated_frontend));
  56. }
  57. public function testFactoryLoadsPlatformBackend()
  58. {
  59. try {
  60. $cache = Zend_Cache::factory('Core', 'Zend-Platform');
  61. } catch (Zend_Cache_Exception $e) {
  62. $message = $e->getMessage();
  63. if (strstr($message, 'Incorrect backend')) {
  64. $this->fail('Zend Platform is a valid backend');
  65. }
  66. }
  67. }
  68. public function testBadFrontend()
  69. {
  70. try {
  71. Zend_Cache::factory('badFrontend', 'File');
  72. } catch (Zend_Exception $e) {
  73. return;
  74. }
  75. $this->fail('Zend_Exception was expected but not thrown');
  76. }
  77. public function testBadBackend()
  78. {
  79. try {
  80. Zend_Cache::factory('Output', 'badBackend');
  81. } catch (Zend_Exception $e) {
  82. return;
  83. }
  84. $this->fail('Zend_Exception was expected but not thrown');
  85. }
  86. }