RegistryTest.php 5.2 KB

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