CallbackTest.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. // Call Zend_Server_Method_CallbackTest::main() if this source file is executed directly.
  3. if (!defined("PHPUnit_MAIN_METHOD")) {
  4. define("PHPUnit_MAIN_METHOD", "Zend_Server_Method_CallbackTest::main");
  5. }
  6. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  7. /** Zend_Server_Method_Callback */
  8. require_once 'Zend/Server/Method/Callback.php';
  9. /**
  10. * Test class for Zend_Server_Method_Callback
  11. */
  12. class Zend_Server_Method_CallbackTest 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_CallbackTest");
  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->callback = new Zend_Server_Method_Callback();
  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 testClassShouldBeNullByDefault()
  44. {
  45. $this->assertNull($this->callback->getClass());
  46. }
  47. public function testClassShouldBeMutable()
  48. {
  49. $this->assertNull($this->callback->getClass());
  50. $this->callback->setClass('Foo');
  51. $this->assertEquals('Foo', $this->callback->getClass());
  52. }
  53. public function testMethodShouldBeNullByDefault()
  54. {
  55. $this->assertNull($this->callback->getMethod());
  56. }
  57. public function testMethodShouldBeMutable()
  58. {
  59. $this->assertNull($this->callback->getMethod());
  60. $this->callback->setMethod('foo');
  61. $this->assertEquals('foo', $this->callback->getMethod());
  62. }
  63. public function testFunctionShouldBeNullByDefault()
  64. {
  65. $this->assertNull($this->callback->getFunction());
  66. }
  67. public function testFunctionShouldBeMutable()
  68. {
  69. $this->assertNull($this->callback->getFunction());
  70. $this->callback->setFunction('foo');
  71. $this->assertEquals('foo', $this->callback->getFunction());
  72. }
  73. public function testTypeShouldBeNullByDefault()
  74. {
  75. $this->assertNull($this->callback->getType());
  76. }
  77. public function testTypeShouldBeMutable()
  78. {
  79. $this->assertNull($this->callback->getType());
  80. $this->callback->setType('instance');
  81. $this->assertEquals('instance', $this->callback->getType());
  82. }
  83. /**
  84. * @expectedException Zend_Server_Exception
  85. */
  86. public function testSettingTypeShouldThrowExceptionWhenInvalidTypeProvided()
  87. {
  88. $this->callback->setType('bogus');
  89. }
  90. public function testCallbackShouldSerializeToArray()
  91. {
  92. $this->callback->setClass('Foo')
  93. ->setMethod('bar')
  94. ->setType('instance');
  95. $test = $this->callback->toArray();
  96. $this->assertTrue(is_array($test));
  97. $this->assertEquals('Foo', $test['class']);
  98. $this->assertEquals('bar', $test['method']);
  99. $this->assertEquals('instance', $test['type']);
  100. }
  101. public function testConstructorShouldSetStateFromOptions()
  102. {
  103. $options = array(
  104. 'type' => 'static',
  105. 'class' => 'Foo',
  106. 'method' => 'bar',
  107. );
  108. $callback = new Zend_Server_Method_Callback($options);
  109. $test = $callback->toArray();
  110. $this->assertSame($options, $test);
  111. }
  112. public function testSettingFunctionShouldSetTypeAsFunction()
  113. {
  114. $this->assertNull($this->callback->getType());
  115. $this->callback->setFunction('foo');
  116. $this->assertEquals('function', $this->callback->getType());
  117. }
  118. }
  119. // Call Zend_Server_Method_CallbackTest::main() if this source file is executed directly.
  120. if (PHPUnit_MAIN_METHOD == "Zend_Server_Method_CallbackTest::main") {
  121. Zend_Server_Method_CallbackTest::main();
  122. }