MiddlewareApplicationTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  5. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  6. *
  7. * Licensed under The MIT License
  8. * For full copyright and license information, please see the LICENSE.txt
  9. * Redistributions of files must retain the above copyright notice.
  10. *
  11. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  12. * @link https://cakephp.org CakePHP(tm) Project
  13. * @since 4.0.0
  14. * @license https://opensource.org/licenses/mit-license.php MIT License
  15. */
  16. namespace Cake\Test\TestCase\Http;
  17. use Cake\Http\MiddlewareApplication;
  18. use Cake\Http\ServerRequestFactory;
  19. use Cake\TestSuite\TestCase;
  20. use Psr\Http\Message\ResponseInterface;
  21. /**
  22. * MiddlewareApplication test.
  23. */
  24. class MiddlewareApplicationTest extends TestCase
  25. {
  26. /**
  27. * Setup
  28. *
  29. * @return void
  30. */
  31. public function setUp(): void
  32. {
  33. parent::setUp();
  34. static::setAppNamespace();
  35. }
  36. /**
  37. * Integration test for a simple controller.
  38. *
  39. * @return void
  40. */
  41. public function testHandle()
  42. {
  43. $request = ServerRequestFactory::fromGlobals(['REQUEST_URI' => '/cakes']);
  44. $request = $request->withAttribute('params', [
  45. 'controller' => 'Cakes',
  46. 'action' => 'index',
  47. 'plugin' => null,
  48. 'pass' => [],
  49. ]);
  50. $app = $this->getMockForAbstractClass(MiddlewareApplication::class);
  51. $result = $app->handle($request);
  52. $this->assertInstanceOf(ResponseInterface::class, $result);
  53. $this->assertSame('Not found', '' . $result->getBody());
  54. $this->assertSame(404, $result->getStatusCode());
  55. }
  56. }