FactoryTest.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Cache
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * Zend_Cache
  24. */
  25. require_once 'Zend/Cache.php';
  26. require_once 'Zend/Cache/Backend/File.php';
  27. class Zend_Cache_Backend_FooBarTest extends Zend_Cache_Backend_File { }
  28. class FooBarTestBackend extends Zend_Cache_Backend_File { }
  29. require_once 'Zend/Cache/Core.php';
  30. class Zend_Cache_Frontend_FooBarTest extends Zend_Cache_Core { }
  31. class FooBarTestFrontend extends Zend_Cache_Core { }
  32. /**
  33. * @category Zend
  34. * @package Zend_Cache
  35. * @subpackage UnitTests
  36. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  37. * @license http://framework.zend.com/license/new-bsd New BSD License
  38. * @group Zend_Cache
  39. */
  40. class Zend_Cache_FactoryTest extends PHPUnit_Framework_TestCase
  41. {
  42. public function setUp()
  43. {
  44. }
  45. public function tearDown()
  46. {
  47. }
  48. public function testFactoryCorrectCall()
  49. {
  50. $generated_frontend = Zend_Cache::factory('Core', 'File');
  51. $this->assertEquals('Zend_Cache_Core', get_class($generated_frontend));
  52. }
  53. public function testFactoryCorrectCallWithCustomBackend()
  54. {
  55. $generated_frontend = Zend_Cache::factory('Core', 'FooBarTest', array(), array(), false, false, true);
  56. $this->assertEquals('Zend_Cache_Core', get_class($generated_frontend));
  57. }
  58. public function testFactoryCorrectCallWithCustomBackend2()
  59. {
  60. $generated_frontend = Zend_Cache::factory('Core', 'FooBarTestBackend', array(), array(), false, true, true);
  61. $this->assertEquals('Zend_Cache_Core', get_class($generated_frontend));
  62. }
  63. public function testFactoryCorrectCallWithCustomFrontend()
  64. {
  65. $generated_frontend = Zend_Cache::factory('FooBarTest', 'File', array(), array(), false, false, true);
  66. $this->assertEquals('Zend_Cache_Frontend_FooBarTest', get_class($generated_frontend));
  67. }
  68. public function testFactoryCorrectCallWithCustomFrontend2()
  69. {
  70. $generated_frontend = Zend_Cache::factory('FooBarTestFrontend', 'File', array(), array(), true, false, true);
  71. $this->assertEquals('FooBarTestFrontend', get_class($generated_frontend));
  72. }
  73. public function testFactoryLoadsPlatformBackend()
  74. {
  75. try {
  76. $cache = Zend_Cache::factory('Core', 'Zend-Platform');
  77. } catch (Zend_Cache_Exception $e) {
  78. $message = $e->getMessage();
  79. if (strstr($message, 'Incorrect backend')) {
  80. $this->fail('Zend Platform is a valid backend');
  81. }
  82. }
  83. }
  84. public function testBadFrontend()
  85. {
  86. try {
  87. Zend_Cache::factory('badFrontend', 'File');
  88. } catch (Zend_Exception $e) {
  89. return;
  90. }
  91. $this->fail('Zend_Exception was expected but not thrown');
  92. }
  93. public function testBadBackend()
  94. {
  95. try {
  96. Zend_Cache::factory('Output', 'badBackend');
  97. } catch (Zend_Exception $e) {
  98. return;
  99. }
  100. $this->fail('Zend_Exception was expected but not thrown');
  101. }
  102. /**
  103. * @group ZF-11988
  104. */
  105. public function testNamespacedFrontendClassAccepted()
  106. {
  107. try {
  108. Zend_Cache::factory('ZF11988\Frontend', 'File', array(), array(), true, false, false);
  109. $this->fail('Zend_Cache_Exception was expected but not thrown');
  110. } catch ( Zend_Cache_Exception $e ) {
  111. $this->assertNotEquals('Invalid frontend name [ZF11988\Frontend]', $e->getMessage());
  112. }
  113. }
  114. /**
  115. * @group ZF-11988
  116. */
  117. public function testNamespacedBackendClassAccepted()
  118. {
  119. try {
  120. Zend_Cache::factory('Output', 'ZF11988\Backend', array(), array(), false, true, false);
  121. $this->fail('Zend_Cache_Exception was expected but not thrown');
  122. } catch ( Zend_Cache_Exception $e ) {
  123. $this->assertNotEquals('Invalid backend name [ZF11988\Backend]', $e->getMessage());
  124. }
  125. }
  126. }