RegistryTest.php 5.4 KB

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