PageRenderTime 39ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/zendframework/zendframework/tests/ZendTest/Server/Method/ParameterTest.php

https://bitbucket.org/pcelta/zf2
PHP | 165 lines | 118 code | 19 blank | 28 comment | 0 complexity | 1be0848f1866342e2a9649af734c597f MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework (http://framework.zend.com/)
  4. *
  5. * @link http://github.com/zendframework/zf2 for the canonical source repository
  6. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  7. * @license http://framework.zend.com/license/new-bsd New BSD License
  8. * @package Zend_Server
  9. */
  10. namespace ZendTest\Server\Method;
  11. use Zend\Server\Method;
  12. /**
  13. * Test class for \Zend\Server\Method\Parameter
  14. *
  15. * @category Zend
  16. * @package Zend_Server
  17. * @subpackage UnitTests
  18. * @group Zend_Server
  19. */
  20. class ParameterTest extends \PHPUnit_Framework_TestCase
  21. {
  22. /**
  23. * Sets up the fixture, for example, open a network connection.
  24. * This method is called before a test is executed.
  25. *
  26. * @return void
  27. */
  28. public function setUp()
  29. {
  30. $this->parameter = new Method\Parameter();
  31. }
  32. /**
  33. * Tears down the fixture, for example, close a network connection.
  34. * This method is called after a test is executed.
  35. *
  36. * @return void
  37. */
  38. public function tearDown()
  39. {
  40. }
  41. public function testDefaultValueShouldBeNullByDefault()
  42. {
  43. $this->assertNull($this->parameter->getDefaultValue());
  44. }
  45. public function testDefaultValueShouldBeMutable()
  46. {
  47. $this->assertNull($this->parameter->getDefaultValue());
  48. $this->parameter->setDefaultValue('foo');
  49. $this->assertEquals('foo', $this->parameter->getDefaultValue());
  50. }
  51. public function testDescriptionShouldBeEmptyStringByDefault()
  52. {
  53. $this->assertSame('', $this->parameter->getDescription());
  54. }
  55. public function testDescriptionShouldBeMutable()
  56. {
  57. $message = 'This is a description';
  58. $this->assertSame('', $this->parameter->getDescription());
  59. $this->parameter->setDescription($message);
  60. $this->assertEquals($message, $this->parameter->getDescription());
  61. }
  62. public function testSettingDescriptionShouldCastToString()
  63. {
  64. $message = 123456;
  65. $this->parameter->setDescription($message);
  66. $test = $this->parameter->getDescription();
  67. $this->assertNotSame($message, $test);
  68. $this->assertEquals($message, $test);
  69. }
  70. public function testNameShouldBeNullByDefault()
  71. {
  72. $this->assertNull($this->parameter->getName());
  73. }
  74. public function testNameShouldBeMutable()
  75. {
  76. $name = 'foo';
  77. $this->assertNull($this->parameter->getName());
  78. $this->parameter->setName($name);
  79. $this->assertEquals($name, $this->parameter->getName());
  80. }
  81. public function testSettingNameShouldCastToString()
  82. {
  83. $name = 123456;
  84. $this->parameter->setName($name);
  85. $test = $this->parameter->getName();
  86. $this->assertNotSame($name, $test);
  87. $this->assertEquals($name, $test);
  88. }
  89. public function testParameterShouldBeRequiredByDefault()
  90. {
  91. $this->assertFalse($this->parameter->isOptional());
  92. }
  93. public function testParameterShouldAllowBeingOptional()
  94. {
  95. $this->assertFalse($this->parameter->isOptional());
  96. $this->parameter->setOptional(true);
  97. $this->assertTrue($this->parameter->isOptional());
  98. }
  99. public function testTypeShouldBeMixedByDefault()
  100. {
  101. $this->assertEquals('mixed', $this->parameter->getType());
  102. }
  103. public function testTypeShouldBeMutable()
  104. {
  105. $type = 'string';
  106. $this->assertEquals('mixed', $this->parameter->getType());
  107. $this->parameter->setType($type);
  108. $this->assertEquals($type, $this->parameter->getType());
  109. }
  110. public function testSettingTypeShouldCastToString()
  111. {
  112. $type = 123456;
  113. $this->parameter->setType($type);
  114. $test = $this->parameter->getType();
  115. $this->assertNotSame($type, $test);
  116. $this->assertEquals($type, $test);
  117. }
  118. public function testParameterShouldSerializeToArray()
  119. {
  120. $type = 'string';
  121. $name = 'foo';
  122. $optional = true;
  123. $defaultValue = 'bar';
  124. $description = 'Foo bar!';
  125. $parameter = compact('type', 'name', 'optional', 'defaultValue', 'description');
  126. $this->parameter->setType($type)
  127. ->setName($name)
  128. ->setOptional($optional)
  129. ->setDefaultValue($defaultValue)
  130. ->setDescription($description);
  131. $test = $this->parameter->toArray();
  132. $this->assertEquals($parameter, $test);
  133. }
  134. public function testConstructorShouldSetObjectStateFromPassedOptions()
  135. {
  136. $type = 'string';
  137. $name = 'foo';
  138. $optional = true;
  139. $defaultValue = 'bar';
  140. $description = 'Foo bar!';
  141. $options = compact('type', 'name', 'optional', 'defaultValue', 'description');
  142. $parameter = new Method\Parameter($options);
  143. $test = $parameter->toArray();
  144. $this->assertEquals($options, $test);
  145. }
  146. }