SignatureTest.php 7.4 KB

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