FactoryTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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-2009 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. /**
  27. * PHPUnit test case
  28. */
  29. require_once 'PHPUnit/Framework/TestCase.php';
  30. require_once 'Zend/Cache/Backend/File.php';
  31. class Zend_Cache_Backend_FooBarTest extends Zend_Cache_Backend_File { }
  32. class FooBarTestBackend extends Zend_Cache_Backend_File { }
  33. require_once 'Zend/Cache/Core.php';
  34. class Zend_Cache_Frontend_FooBarTest extends Zend_Cache_Core { }
  35. class FooBarTestFrontend extends Zend_Cache_Core { }
  36. /**
  37. * @category Zend
  38. * @package Zend_Cache
  39. * @subpackage UnitTests
  40. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  41. * @license http://framework.zend.com/license/new-bsd New BSD License
  42. * @group Zend_Cache
  43. */
  44. class Zend_Cache_FactoryTest extends PHPUnit_Framework_TestCase
  45. {
  46. public function setUp()
  47. {
  48. }
  49. public function tearDown()
  50. {
  51. }
  52. public function testFactoryCorrectCall()
  53. {
  54. $generated_frontend = Zend_Cache::factory('Core', 'File');
  55. $this->assertEquals('Zend_Cache_Core', get_class($generated_frontend));
  56. }
  57. public function testFactoryCorrectCallWithCustomBackend()
  58. {
  59. $generated_frontend = Zend_Cache::factory('Core', 'FooBarTest', array(), array(), false, false, true);
  60. $this->assertEquals('Zend_Cache_Core', get_class($generated_frontend));
  61. }
  62. public function testFactoryCorrectCallWithCustomBackend2()
  63. {
  64. $generated_frontend = Zend_Cache::factory('Core', 'FooBarTestBackend', array(), array(), false, true, true);
  65. $this->assertEquals('Zend_Cache_Core', get_class($generated_frontend));
  66. }
  67. public function testFactoryCorrectCallWithCustomFrontend()
  68. {
  69. $generated_frontend = Zend_Cache::factory('FooBarTest', 'File', array(), array(), false, false, true);
  70. $this->assertEquals('Zend_Cache_Frontend_FooBarTest', get_class($generated_frontend));
  71. }
  72. public function testFactoryCorrectCallWithCustomFrontend2()
  73. {
  74. $generated_frontend = Zend_Cache::factory('FooBarTestFrontend', 'File', array(), array(), true, false, true);
  75. $this->assertEquals('FooBarTestFrontend', get_class($generated_frontend));
  76. }
  77. public function testFactoryLoadsPlatformBackend()
  78. {
  79. try {
  80. $cache = Zend_Cache::factory('Core', 'Zend-Platform');
  81. } catch (Zend_Cache_Exception $e) {
  82. $message = $e->getMessage();
  83. if (strstr($message, 'Incorrect backend')) {
  84. $this->fail('Zend Platform is a valid backend');
  85. }
  86. }
  87. }
  88. public function testBadFrontend()
  89. {
  90. try {
  91. Zend_Cache::factory('badFrontend', 'File');
  92. } catch (Zend_Exception $e) {
  93. return;
  94. }
  95. $this->fail('Zend_Exception was expected but not thrown');
  96. }
  97. public function testBadBackend()
  98. {
  99. try {
  100. Zend_Cache::factory('Output', 'badBackend');
  101. } catch (Zend_Exception $e) {
  102. return;
  103. }
  104. $this->fail('Zend_Exception was expected but not thrown');
  105. }
  106. }