CallbackTest.php 5.0 KB

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