ParameterTest.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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_Server
  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. // Call Zend_Server_Method_ParameterTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_Server_Method_ParameterTest::main");
  25. }
  26. /** Zend_Server_Method_Parameter */
  27. require_once 'Zend/Server/Method/Parameter.php';
  28. /**
  29. * Test class for Zend_Server_Method_Parameter
  30. *
  31. * @category Zend
  32. * @package Zend_Server
  33. * @subpackage UnitTests
  34. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. * @group Zend_Server
  37. */
  38. class Zend_Server_Method_ParameterTest extends PHPUnit_Framework_TestCase
  39. {
  40. /**
  41. * Runs the test methods of this class.
  42. *
  43. * @return void
  44. */
  45. public static function main()
  46. {
  47. $suite = new PHPUnit_Framework_TestSuite("Zend_Server_Method_ParameterTest");
  48. $result = PHPUnit_TextUI_TestRunner::run($suite);
  49. }
  50. /**
  51. * Sets up the fixture, for example, open a network connection.
  52. * This method is called before a test is executed.
  53. *
  54. * @return void
  55. */
  56. public function setUp()
  57. {
  58. $this->parameter = new Zend_Server_Method_Parameter();
  59. }
  60. /**
  61. * Tears down the fixture, for example, close a network connection.
  62. * This method is called after a test is executed.
  63. *
  64. * @return void
  65. */
  66. public function tearDown()
  67. {
  68. }
  69. public function testDefaultValueShouldBeNullByDefault()
  70. {
  71. $this->assertNull($this->parameter->getDefaultValue());
  72. }
  73. public function testDefaultValueShouldBeMutable()
  74. {
  75. $this->assertNull($this->parameter->getDefaultValue());
  76. $this->parameter->setDefaultValue('foo');
  77. $this->assertEquals('foo', $this->parameter->getDefaultValue());
  78. }
  79. public function testDescriptionShouldBeEmptyStringByDefault()
  80. {
  81. $this->assertSame('', $this->parameter->getDescription());
  82. }
  83. public function testDescriptionShouldBeMutable()
  84. {
  85. $message = 'This is a description';
  86. $this->assertSame('', $this->parameter->getDescription());
  87. $this->parameter->setDescription($message);
  88. $this->assertEquals($message, $this->parameter->getDescription());
  89. }
  90. public function testSettingDescriptionShouldCastToString()
  91. {
  92. $message = 123456;
  93. $this->parameter->setDescription($message);
  94. $test = $this->parameter->getDescription();
  95. $this->assertNotSame($message, $test);
  96. $this->assertEquals($message, $test);
  97. }
  98. public function testNameShouldBeNullByDefault()
  99. {
  100. $this->assertNull($this->parameter->getName());
  101. }
  102. public function testNameShouldBeMutable()
  103. {
  104. $name = 'foo';
  105. $this->assertNull($this->parameter->getName());
  106. $this->parameter->setName($name);
  107. $this->assertEquals($name, $this->parameter->getName());
  108. }
  109. public function testSettingNameShouldCastToString()
  110. {
  111. $name = 123456;
  112. $this->parameter->setName($name);
  113. $test = $this->parameter->getName();
  114. $this->assertNotSame($name, $test);
  115. $this->assertEquals($name, $test);
  116. }
  117. public function testParameterShouldBeRequiredByDefault()
  118. {
  119. $this->assertFalse($this->parameter->isOptional());
  120. }
  121. public function testParameterShouldAllowBeingOptional()
  122. {
  123. $this->assertFalse($this->parameter->isOptional());
  124. $this->parameter->setOptional(true);
  125. $this->assertTrue($this->parameter->isOptional());
  126. }
  127. public function testTypeShouldBeMixedByDefault()
  128. {
  129. $this->assertEquals('mixed', $this->parameter->getType());
  130. }
  131. public function testTypeShouldBeMutable()
  132. {
  133. $type = 'string';
  134. $this->assertEquals('mixed', $this->parameter->getType());
  135. $this->parameter->setType($type);
  136. $this->assertEquals($type, $this->parameter->getType());
  137. }
  138. public function testSettingTypeShouldCastToString()
  139. {
  140. $type = 123456;
  141. $this->parameter->setType($type);
  142. $test = $this->parameter->getType();
  143. $this->assertNotSame($type, $test);
  144. $this->assertEquals($type, $test);
  145. }
  146. public function testParameterShouldSerializeToArray()
  147. {
  148. $type = 'string';
  149. $name = 'foo';
  150. $optional = true;
  151. $defaultValue = 'bar';
  152. $description = 'Foo bar!';
  153. $parameter = compact('type', 'name', 'optional', 'defaultValue', 'description');
  154. $this->parameter->setType($type)
  155. ->setName($name)
  156. ->setOptional($optional)
  157. ->setDefaultValue($defaultValue)
  158. ->setDescription($description);
  159. $test = $this->parameter->toArray();
  160. $this->assertEquals($parameter, $test);
  161. }
  162. public function testConstructorShouldSetObjectStateFromPassedOptions()
  163. {
  164. $type = 'string';
  165. $name = 'foo';
  166. $optional = true;
  167. $defaultValue = 'bar';
  168. $description = 'Foo bar!';
  169. $options = compact('type', 'name', 'optional', 'defaultValue', 'description');
  170. $parameter = new Zend_Server_Method_Parameter($options);
  171. $test = $parameter->toArray();
  172. $this->assertEquals($options, $test);
  173. }
  174. }
  175. // Call Zend_Server_Method_ParameterTest::main() if this source file is executed directly.
  176. if (PHPUnit_MAIN_METHOD == "Zend_Server_Method_ParameterTest::main") {
  177. Zend_Server_Method_ParameterTest::main();
  178. }