PageRenderTime 40ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/Zend/Server/Method/ParameterTest.php

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