CallbackTest.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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_CallbackTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_Server_Method_CallbackTest::main");
  25. }
  26. /** Zend_Server_Method_Callback */
  27. require_once 'Zend/Server/Method/Callback.php';
  28. /**
  29. * Test class for Zend_Server_Method_Callback
  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_CallbackTest 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_CallbackTest");
  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->callback = new Zend_Server_Method_Callback();
  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 testClassShouldBeNullByDefault()
  70. {
  71. $this->assertNull($this->callback->getClass());
  72. }
  73. public function testClassShouldBeMutable()
  74. {
  75. $this->assertNull($this->callback->getClass());
  76. $this->callback->setClass('Foo');
  77. $this->assertEquals('Foo', $this->callback->getClass());
  78. }
  79. public function testMethodShouldBeNullByDefault()
  80. {
  81. $this->assertNull($this->callback->getMethod());
  82. }
  83. public function testMethodShouldBeMutable()
  84. {
  85. $this->assertNull($this->callback->getMethod());
  86. $this->callback->setMethod('foo');
  87. $this->assertEquals('foo', $this->callback->getMethod());
  88. }
  89. public function testFunctionShouldBeNullByDefault()
  90. {
  91. $this->assertNull($this->callback->getFunction());
  92. }
  93. public function testFunctionShouldBeMutable()
  94. {
  95. $this->assertNull($this->callback->getFunction());
  96. $this->callback->setFunction('foo');
  97. $this->assertEquals('foo', $this->callback->getFunction());
  98. }
  99. public function testTypeShouldBeNullByDefault()
  100. {
  101. $this->assertNull($this->callback->getType());
  102. }
  103. public function testTypeShouldBeMutable()
  104. {
  105. $this->assertNull($this->callback->getType());
  106. $this->callback->setType('instance');
  107. $this->assertEquals('instance', $this->callback->getType());
  108. }
  109. /**
  110. * @expectedException Zend_Server_Exception
  111. */
  112. public function testSettingTypeShouldThrowExceptionWhenInvalidTypeProvided()
  113. {
  114. $this->callback->setType('bogus');
  115. }
  116. public function testCallbackShouldSerializeToArray()
  117. {
  118. $this->callback->setClass('Foo')
  119. ->setMethod('bar')
  120. ->setType('instance');
  121. $test = $this->callback->toArray();
  122. $this->assertTrue(is_array($test));
  123. $this->assertEquals('Foo', $test['class']);
  124. $this->assertEquals('bar', $test['method']);
  125. $this->assertEquals('instance', $test['type']);
  126. }
  127. public function testConstructorShouldSetStateFromOptions()
  128. {
  129. $options = array(
  130. 'type' => 'static',
  131. 'class' => 'Foo',
  132. 'method' => 'bar',
  133. );
  134. $callback = new Zend_Server_Method_Callback($options);
  135. $test = $callback->toArray();
  136. $this->assertSame($options, $test);
  137. }
  138. public function testSettingFunctionShouldSetTypeAsFunction()
  139. {
  140. $this->assertNull($this->callback->getType());
  141. $this->callback->setFunction('foo');
  142. $this->assertEquals('function', $this->callback->getType());
  143. }
  144. }
  145. // Call Zend_Server_Method_CallbackTest::main() if this source file is executed directly.
  146. if (PHPUnit_MAIN_METHOD == "Zend_Server_Method_CallbackTest::main") {
  147. Zend_Server_Method_CallbackTest::main();
  148. }