SignatureTest.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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-2008 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_Provider_Repository
  27. */
  28. require_once 'Zend/Tool/Framework/Provider/Repository.php';
  29. require_once 'Zend/Tool/Framework/Registry.php';
  30. require_once 'Zend/Tool/Framework/Action/Repository.php';
  31. require_once '_files/ProviderOne.php';
  32. require_once '_files/ProviderTwo.php';
  33. require_once '_files/ProviderAltName.php';
  34. require_once '_files/ProviderFullFeatured.php';
  35. require_once '_files/ProviderFullFeatured2.php';
  36. require_once '_files/ProviderFullFeaturedBadSpecialties.php';
  37. require_once '_files/ProviderFullFeaturedBadSpecialties2.php';
  38. /**
  39. * @category Zend
  40. * @package Zend_Tool
  41. * @subpackage UnitTests
  42. * @copyright Copyright (c) 2005-2008 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_Framework
  46. * @group Zend_Tool_Framework_Action
  47. */
  48. class Zend_Tool_Framework_Provider_SignatureTest extends PHPUnit_Framework_TestCase
  49. {
  50. protected $_registry = null;
  51. /**
  52. * @var Zend_Tool_Framework_Provider_Signature
  53. */
  54. protected $_targetSignature = null;
  55. public function setup()
  56. {
  57. // setup the registry components required to test with
  58. $this->_registry = new Zend_Tool_Framework_Registry();
  59. $this->_registry->setActionRepository(new Zend_Tool_Framework_Action_Repository());
  60. $this->_targetSignature = new Zend_Tool_Framework_Provider_Signature(new Zend_Tool_Framework_Provider_ProviderFullFeatured());
  61. $this->_targetSignature->setRegistry($this->_registry);
  62. $this->_targetSignature->process();
  63. }
  64. public function teardown()
  65. {
  66. $this->_registry->reset();
  67. }
  68. public function testSignatureCanBeCreatedFromProvider()
  69. {
  70. $signature = new Zend_Tool_Framework_Provider_Signature(new Zend_Tool_Framework_Provider_ProviderOne());
  71. $signature->setRegistry($this->_registry);
  72. $signature->process();
  73. $signature->process();
  74. $this->assertEquals('ProviderOne', $signature->getName());
  75. }
  76. public function testSignatureCanBeCreatedFromProviderWhenOverridingName()
  77. {
  78. $signature = new Zend_Tool_Framework_Provider_Signature(new Zend_Tool_Framework_Provider_ProviderFullFeatured());
  79. $signature->setRegistry($this->_registry);
  80. $signature->process();
  81. $this->assertEquals('FooBarBaz', $signature->getName());
  82. }
  83. public function testGetProviderReturnsProvider()
  84. {
  85. $signature = new Zend_Tool_Framework_Provider_Signature(new Zend_Tool_Framework_Provider_ProviderOne());
  86. $signature->setRegistry($this->_registry);
  87. $signature->process();
  88. $this->assertTrue($signature->getProvider() instanceof Zend_Tool_Framework_Provider_ProviderOne);
  89. }
  90. public function testGetProviderReflectionWillReturnZendReflectionClassObject()
  91. {
  92. $signature = new Zend_Tool_Framework_Provider_Signature(new Zend_Tool_Framework_Provider_ProviderOne());
  93. $signature->setRegistry($this->_registry);
  94. $signature->process();
  95. $this->assertTrue($signature->getProviderReflection() instanceof Zend_Reflection_Class);
  96. }
  97. public function testGetSpecialtiesReturnsParsedSpecialties()
  98. {
  99. $this->assertEquals(array('_Global', 'Hi', 'BloodyMurder', 'ForYourTeam'), $this->_targetSignature->getSpecialties());
  100. }
  101. public function testGetSpecialtiesReturnsParsedSpecialtiesFromMethodInsteadOfProperty()
  102. {
  103. $signature = new Zend_Tool_Framework_Provider_Signature(new Zend_Tool_Framework_Provider_ProviderFullFeatured2());
  104. $signature->setRegistry($this->_registry);
  105. $signature->process();
  106. $this->assertEquals(array('_Global', 'Hi', 'BloodyMurder', 'ForYourTeam'), $signature->getSpecialties());
  107. }
  108. /**
  109. * @expectedException Zend_Tool_Framework_Provider_Exception
  110. */
  111. public function testGetSpecialtiesReturnsParsedSpecialtiesThrowsExceptionOnBadPropertyValue()
  112. {
  113. $signature = new Zend_Tool_Framework_Provider_Signature(new Zend_Tool_Framework_Provider_ProviderFullFeaturedBadSpecialties());
  114. $signature->setRegistry($this->_registry);
  115. $signature->process();
  116. }
  117. /**
  118. * @expectedException Zend_Tool_Framework_Provider_Exception
  119. */
  120. public function testGetSpecialtiesReturnsParsedSpecialtiesThrowsExceptionOnBadReturnValue()
  121. {
  122. $signature = new Zend_Tool_Framework_Provider_Signature(new Zend_Tool_Framework_Provider_ProviderFullFeaturedBadSpecialties2());
  123. $signature->setRegistry($this->_registry);
  124. $signature->process();
  125. }
  126. public function testGetActionsWillReturnProperActions()
  127. {
  128. $actionArray = $this->_targetSignature->getActions();
  129. $action = array_shift($actionArray);
  130. $this->assertTrue($action instanceof Zend_Tool_Framework_Action_Base);
  131. $this->assertEquals('Say', $action->getName());
  132. $action = array_shift($actionArray);
  133. $this->assertTrue($action instanceof Zend_Tool_Framework_Action_Base);
  134. $this->assertEquals('Scream', $action->getName());
  135. }
  136. public function testGetActionableMethodsReturnsAllActionableMethods()
  137. {
  138. $this->assertEquals(5, count($this->_targetSignature->getActionableMethods()));
  139. $actionableMethods = $this->_targetSignature->getActionableMethods();
  140. $actionableMethod = array_shift($actionableMethods);
  141. $this->assertEquals('say', $actionableMethod['methodName']);
  142. $actionableMethod = array_shift($actionableMethods);
  143. $this->assertEquals('scream', $actionableMethod['methodName']);
  144. $actionableMethod = array_shift($actionableMethods);
  145. $this->assertEquals('sayHi', $actionableMethod['methodName']);
  146. $actionableMethod = array_shift($actionableMethods);
  147. $this->assertEquals('screamBloodyMurder', $actionableMethod['methodName']);
  148. $actionableMethod = array_shift($actionableMethods);
  149. $this->assertEquals('screamForYourTeam', $actionableMethod['methodName']);
  150. }
  151. public function testGetActionableMethodReturnsCorrectActionableMethod()
  152. {
  153. $actionableMethod = $this->_targetSignature->getActionableMethod('scream');
  154. $this->assertEquals('Scream', $actionableMethod['actionName']);
  155. $this->assertFalse($this->_targetSignature->getActionableMethod('Foo'));
  156. }
  157. public function testGetActionableMethodByActionNameReturnsCorrectActionableMethod()
  158. {
  159. $actionableMethod = $this->_targetSignature->getActionableMethodByActionName('Scream');
  160. $this->assertEquals('scream', $actionableMethod['methodName']);
  161. $this->assertFalse($this->_targetSignature->getActionableMethodByActionName('Foo'));
  162. }
  163. }