RegistryTest.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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_Tool
  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. */
  21. /**
  22. * @see TestHelper.php
  23. */
  24. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  25. /**
  26. * @see Zend_Tool_Framework_Registry
  27. */
  28. require_once 'Zend/Tool/Framework/Registry.php';
  29. /** Other Requirements */
  30. require_once 'Zend/Tool/Framework/Action/Repository.php';
  31. require_once 'Zend/Tool/Framework/Provider/Repository.php';
  32. require_once 'Zend/Tool/Framework/Manifest/Repository.php';
  33. require_once 'Zend/Tool/Framework/Client/Request.php';
  34. require_once 'Zend/Tool/Framework/Client/Response.php';
  35. require_once '_files/EmptyClient.php';
  36. require_once '_files/EmptyLoader.php';
  37. /**
  38. * @category Zend
  39. * @package Zend_Tool
  40. * @subpackage UnitTests
  41. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  42. * @license http://framework.zend.com/license/new-bsd New BSD License
  43. *
  44. * @group Zend_Tool_Framework
  45. * @group Zend_Tool_Framework_Action
  46. */
  47. class Zend_Tool_Framework_RegistryTest extends PHPUnit_Framework_TestCase
  48. {
  49. public function setup()
  50. {
  51. $this->_registry = new Zend_Tool_Framework_Registry();
  52. }
  53. public function teardown()
  54. {
  55. $this->_registry->reset();
  56. }
  57. public function testRegistryCanGetAndSetClient()
  58. {
  59. $this->assertNull($this->_registry->getClient());
  60. $this->_registry->setClient($client = new Zend_Tool_Framework_EmptyClient());
  61. $this->assertTrue($this->_registry->getClient() === $client);
  62. }
  63. public function testRegistryCanGetAndSetLoader()
  64. {
  65. $this->assertTrue($this->_registry->getLoader() instanceof Zend_Tool_Framework_Loader_Abstract);
  66. $this->_registry->setLoader($loader = new Zend_Tool_Framework_EmptyLoader());
  67. $this->assertTrue($this->_registry->getLoader() === $loader);
  68. }
  69. public function testRegistryCanGetAndSetActionRepository()
  70. {
  71. $this->assertTrue($this->_registry->getActionRepository() instanceof Zend_Tool_Framework_Action_Repository);
  72. $this->_registry->setActionRepository($repo = new Zend_Tool_Framework_Action_Repository());
  73. $this->assertTrue($this->_registry->getActionRepository() === $repo);
  74. }
  75. public function testRegistryCanGetAndSetProviderRepository()
  76. {
  77. $this->assertTrue($this->_registry->getProviderRepository() instanceof Zend_Tool_Framework_Provider_Repository);
  78. $this->_registry->setProviderRepository($repo = new Zend_Tool_Framework_Provider_Repository());
  79. $this->assertTrue($this->_registry->getProviderRepository() === $repo);
  80. }
  81. public function testRegistryCanGetAndSetManifestRepository()
  82. {
  83. $this->assertTrue($this->_registry->getManifestRepository() instanceof Zend_Tool_Framework_Manifest_Repository);
  84. $this->_registry->setManifestRepository($repo = new Zend_Tool_Framework_Manifest_Repository());
  85. $this->assertTrue($this->_registry->getManifestRepository() === $repo);
  86. }
  87. public function testRegistryCanGetAndSetRequest()
  88. {
  89. $this->assertTrue($this->_registry->getRequest() instanceof Zend_Tool_Framework_Client_Request);
  90. $this->_registry->setRequest($req = new Zend_Tool_Framework_Client_Request());
  91. $this->assertTrue($this->_registry->getRequest() === $req);
  92. }
  93. public function testRegistryCanGetAndSetResponse()
  94. {
  95. $this->assertTrue($this->_registry->getResponse() instanceof Zend_Tool_Framework_Client_Response);
  96. $this->_registry->setResponse($resp = new Zend_Tool_Framework_Client_Response());
  97. $this->assertTrue($this->_registry->getResponse() === $resp);
  98. }
  99. public function testMagicGetAndSetOfRegistryItems()
  100. {
  101. $this->assertTrue($this->_registry->request instanceof Zend_Tool_Framework_Client_Request);
  102. $this->_registry->request = new Zend_Tool_Framework_Client_Request();
  103. $this->assertTrue($this->_registry->request instanceof Zend_Tool_Framework_Client_Request);
  104. }
  105. /**
  106. * @expectedException Zend_Tool_Framework_Exception
  107. */
  108. public function testMagicGetThrowsExceptionOnNonExistentItem()
  109. {
  110. $foo = $this->_registry->foo;
  111. }
  112. /**
  113. * @expectedException Zend_Tool_Framework_Exception
  114. */
  115. public function testMagicSetThrowsExceptionOnNonExistentItem()
  116. {
  117. $this->_registry->foo = 'foo';
  118. }
  119. /**
  120. * @expectedException Zend_Tool_Framework_Exception
  121. */
  122. public function testIsObjectRegistryEnablableWillThrowExceptionsOnNonObject()
  123. {
  124. $this->_registry->isObjectRegistryEnablable('foo');
  125. }
  126. /**
  127. * @expectedException Zend_Tool_Framework_Exception
  128. */
  129. public function testEnableRegistryOnObjectWillThrowExceptionsOnNonObject()
  130. {
  131. $this->_registry->enableRegistryOnObject(new ArrayObject());
  132. }
  133. }