ControllerTest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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_Rest
  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. /** Zend_Rest_Controller */
  23. require_once 'Zend/Rest/Controller.php';
  24. /** Zend_Controller_Request_HttpTestCase */
  25. require_once 'Zend/Controller/Request/HttpTestCase.php';
  26. /** Zend_Controller_Response_HttpTestCase */
  27. require_once 'Zend/Controller/Response/HttpTestCase.php';
  28. // Call Zend_Rest_ControllerTest::main() if this source file is executed directly.
  29. if (!defined("PHPUnit_MAIN_METHOD")) {
  30. define("PHPUnit_MAIN_METHOD", "Zend_Rest_ControllerTest::main");
  31. }
  32. /**
  33. * @category Zend
  34. * @package Zend_Rest
  35. * @subpackage UnitTests
  36. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  37. * @license http://framework.zend.com/license/new-bsd New BSD License
  38. */
  39. class Zend_Rest_TestController extends Zend_Rest_Controller
  40. {
  41. public $testValue = '';
  42. public function __construct(Zend_Controller_Request_Abstract $request,
  43. Zend_Controller_Response_Abstract $response,
  44. array $invokeArgs = array())
  45. {
  46. $this->testValue = '';
  47. }
  48. public function indexAction()
  49. {
  50. $this->testValue = 'indexAction';
  51. }
  52. public function getAction()
  53. {
  54. $this->testValue = 'getAction';
  55. }
  56. public function headAction()
  57. {
  58. $this->testValue = 'headAction';
  59. }
  60. public function postAction()
  61. {
  62. $this->testValue = 'postAction';
  63. }
  64. public function putAction()
  65. {
  66. $this->testValue = 'putAction';
  67. }
  68. public function deleteAction()
  69. {
  70. $this->testValue = 'deleteAction';
  71. }
  72. }
  73. /**
  74. * @category Zend
  75. * @package Zend_Rest
  76. * @subpackage UnitTests
  77. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  78. * @license http://framework.zend.com/license/new-bsd New BSD License
  79. * @group Zend_Rest
  80. */
  81. class Zend_Rest_ControllerTest extends PHPUnit_Framework_TestCase
  82. {
  83. protected $_testController;
  84. /**
  85. * Runs the test methods of this class.
  86. *
  87. * @access public
  88. * @static
  89. */
  90. public static function main()
  91. {
  92. $suite = new PHPUnit_Framework_TestSuite("Zend_Rest_ControllerTest");
  93. $result = PHPUnit_TextUI_TestRunner::run($suite);
  94. }
  95. public function setUp()
  96. {
  97. $request = new Zend_Controller_Request_HttpTestCase();
  98. $response = new Zend_Controller_Response_HttpTestCase();
  99. $this->_testController = new Zend_Rest_TestController($request, $response);
  100. }
  101. public function test_action_methods()
  102. {
  103. $this->_testController->indexAction();
  104. $this->assertEquals('indexAction', $this->_testController->testValue);
  105. $this->_testController->getAction();
  106. $this->assertEquals('getAction', $this->_testController->testValue);
  107. $this->_testController->headAction();
  108. $this->assertEquals('headAction', $this->_testController->testValue);
  109. $this->_testController->postAction();
  110. $this->assertEquals('postAction', $this->_testController->testValue);
  111. $this->_testController->putAction();
  112. $this->assertEquals('putAction', $this->_testController->testValue);
  113. $this->_testController->deleteAction();
  114. $this->assertEquals('deleteAction', $this->_testController->testValue);
  115. }
  116. }
  117. // Call Zend_Rest_ControllerTest::main() if this source file is executed directly.
  118. if (PHPUnit_MAIN_METHOD == "Zend_Rest_ControllerTest::main") {
  119. Zend_Rest_ControllerTest::main();
  120. }