PageRenderTime 1511ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/pcelta/zf2
PHP | 130 lines | 86 code | 16 blank | 28 comment | 0 complexity | 6533a17dcbc195599a8f5c369d33c649 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\Callback
  14. *
  15. * @category Zend
  16. * @package Zend_Server
  17. * @subpackage UnitTests
  18. * @group Zend_Server
  19. */
  20. class CallbackTest 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->callback = new Method\Callback();
  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 testClassShouldBeNullByDefault()
  42. {
  43. $this->assertNull($this->callback->getClass());
  44. }
  45. public function testClassShouldBeMutable()
  46. {
  47. $this->assertNull($this->callback->getClass());
  48. $this->callback->setClass('Foo');
  49. $this->assertEquals('Foo', $this->callback->getClass());
  50. }
  51. public function testMethodShouldBeNullByDefault()
  52. {
  53. $this->assertNull($this->callback->getMethod());
  54. }
  55. public function testMethodShouldBeMutable()
  56. {
  57. $this->assertNull($this->callback->getMethod());
  58. $this->callback->setMethod('foo');
  59. $this->assertEquals('foo', $this->callback->getMethod());
  60. }
  61. public function testFunctionShouldBeNullByDefault()
  62. {
  63. $this->assertNull($this->callback->getFunction());
  64. }
  65. public function testFunctionShouldBeMutable()
  66. {
  67. $this->assertNull($this->callback->getFunction());
  68. $this->callback->setFunction('foo');
  69. $this->assertEquals('foo', $this->callback->getFunction());
  70. }
  71. public function testTypeShouldBeNullByDefault()
  72. {
  73. $this->assertNull($this->callback->getType());
  74. }
  75. public function testTypeShouldBeMutable()
  76. {
  77. $this->assertNull($this->callback->getType());
  78. $this->callback->setType('instance');
  79. $this->assertEquals('instance', $this->callback->getType());
  80. }
  81. public function testSettingTypeShouldThrowExceptionWhenInvalidTypeProvided()
  82. {
  83. $this->setExpectedException('Zend\Server\Exception\InvalidArgumentException', 'Invalid method callback type');
  84. $this->callback->setType('bogus');
  85. }
  86. public function testCallbackShouldSerializeToArray()
  87. {
  88. $this->callback->setClass('Foo')
  89. ->setMethod('bar')
  90. ->setType('instance');
  91. $test = $this->callback->toArray();
  92. $this->assertTrue(is_array($test));
  93. $this->assertEquals('Foo', $test['class']);
  94. $this->assertEquals('bar', $test['method']);
  95. $this->assertEquals('instance', $test['type']);
  96. }
  97. public function testConstructorShouldSetStateFromOptions()
  98. {
  99. $options = array(
  100. 'type' => 'static',
  101. 'class' => 'Foo',
  102. 'method' => 'bar',
  103. );
  104. $callback = new Method\Callback($options);
  105. $test = $callback->toArray();
  106. $this->assertSame($options, $test);
  107. }
  108. public function testSettingFunctionShouldSetTypeAsFunction()
  109. {
  110. $this->assertNull($this->callback->getType());
  111. $this->callback->setFunction('foo');
  112. $this->assertEquals('function', $this->callback->getType());
  113. }
  114. }