SignatureTest.php 7.3 KB

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