ParameterTest.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. // Call Zend_Server_Method_ParameterTest::main() if this source file is executed directly.
  3. if (!defined("PHPUnit_MAIN_METHOD")) {
  4. define("PHPUnit_MAIN_METHOD", "Zend_Server_Method_ParameterTest::main");
  5. }
  6. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  7. /** Zend_Server_Method_Parameter */
  8. require_once 'Zend/Server/Method/Parameter.php';
  9. /**
  10. * Test class for Zend_Server_Method_Parameter
  11. */
  12. class Zend_Server_Method_ParameterTest extends PHPUnit_Framework_TestCase
  13. {
  14. /**
  15. * Runs the test methods of this class.
  16. *
  17. * @return void
  18. */
  19. public static function main()
  20. {
  21. $suite = new PHPUnit_Framework_TestSuite("Zend_Server_Method_ParameterTest");
  22. $result = PHPUnit_TextUI_TestRunner::run($suite);
  23. }
  24. /**
  25. * Sets up the fixture, for example, open a network connection.
  26. * This method is called before a test is executed.
  27. *
  28. * @return void
  29. */
  30. public function setUp()
  31. {
  32. $this->parameter = new Zend_Server_Method_Parameter();
  33. }
  34. /**
  35. * Tears down the fixture, for example, close a network connection.
  36. * This method is called after a test is executed.
  37. *
  38. * @return void
  39. */
  40. public function tearDown()
  41. {
  42. }
  43. public function testDefaultValueShouldBeNullByDefault()
  44. {
  45. $this->assertNull($this->parameter->getDefaultValue());
  46. }
  47. public function testDefaultValueShouldBeMutable()
  48. {
  49. $this->assertNull($this->parameter->getDefaultValue());
  50. $this->parameter->setDefaultValue('foo');
  51. $this->assertEquals('foo', $this->parameter->getDefaultValue());
  52. }
  53. public function testDescriptionShouldBeEmptyStringByDefault()
  54. {
  55. $this->assertSame('', $this->parameter->getDescription());
  56. }
  57. public function testDescriptionShouldBeMutable()
  58. {
  59. $message = 'This is a description';
  60. $this->assertSame('', $this->parameter->getDescription());
  61. $this->parameter->setDescription($message);
  62. $this->assertEquals($message, $this->parameter->getDescription());
  63. }
  64. public function testSettingDescriptionShouldCastToString()
  65. {
  66. $message = 123456;
  67. $this->parameter->setDescription($message);
  68. $test = $this->parameter->getDescription();
  69. $this->assertNotSame($message, $test);
  70. $this->assertEquals($message, $test);
  71. }
  72. public function testNameShouldBeNullByDefault()
  73. {
  74. $this->assertNull($this->parameter->getName());
  75. }
  76. public function testNameShouldBeMutable()
  77. {
  78. $name = 'foo';
  79. $this->assertNull($this->parameter->getName());
  80. $this->parameter->setName($name);
  81. $this->assertEquals($name, $this->parameter->getName());
  82. }
  83. public function testSettingNameShouldCastToString()
  84. {
  85. $name = 123456;
  86. $this->parameter->setName($name);
  87. $test = $this->parameter->getName();
  88. $this->assertNotSame($name, $test);
  89. $this->assertEquals($name, $test);
  90. }
  91. public function testParameterShouldBeRequiredByDefault()
  92. {
  93. $this->assertFalse($this->parameter->isOptional());
  94. }
  95. public function testParameterShouldAllowBeingOptional()
  96. {
  97. $this->assertFalse($this->parameter->isOptional());
  98. $this->parameter->setOptional(true);
  99. $this->assertTrue($this->parameter->isOptional());
  100. }
  101. public function testTypeShouldBeMixedByDefault()
  102. {
  103. $this->assertEquals('mixed', $this->parameter->getType());
  104. }
  105. public function testTypeShouldBeMutable()
  106. {
  107. $type = 'string';
  108. $this->assertEquals('mixed', $this->parameter->getType());
  109. $this->parameter->setType($type);
  110. $this->assertEquals($type, $this->parameter->getType());
  111. }
  112. public function testSettingTypeShouldCastToString()
  113. {
  114. $type = 123456;
  115. $this->parameter->setType($type);
  116. $test = $this->parameter->getType();
  117. $this->assertNotSame($type, $test);
  118. $this->assertEquals($type, $test);
  119. }
  120. public function testParameterShouldSerializeToArray()
  121. {
  122. $type = 'string';
  123. $name = 'foo';
  124. $optional = true;
  125. $defaultValue = 'bar';
  126. $description = 'Foo bar!';
  127. $parameter = compact('type', 'name', 'optional', 'defaultValue', 'description');
  128. $this->parameter->setType($type)
  129. ->setName($name)
  130. ->setOptional($optional)
  131. ->setDefaultValue($defaultValue)
  132. ->setDescription($description);
  133. $test = $this->parameter->toArray();
  134. $this->assertEquals($parameter, $test);
  135. }
  136. public function testConstructorShouldSetObjectStateFromPassedOptions()
  137. {
  138. $type = 'string';
  139. $name = 'foo';
  140. $optional = true;
  141. $defaultValue = 'bar';
  142. $description = 'Foo bar!';
  143. $options = compact('type', 'name', 'optional', 'defaultValue', 'description');
  144. $parameter = new Zend_Server_Method_Parameter($options);
  145. $test = $parameter->toArray();
  146. $this->assertEquals($options, $test);
  147. }
  148. }
  149. // Call Zend_Server_Method_ParameterTest::main() if this source file is executed directly.
  150. if (PHPUnit_MAIN_METHOD == "Zend_Server_Method_ParameterTest::main") {
  151. Zend_Server_Method_ParameterTest::main();
  152. }