MiddlewareApplicationTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. public function setUp(): void
  30. {
  31. parent::setUp();
  32. static::setAppNamespace();
  33. }
  34. /**
  35. * Integration test for a simple controller.
  36. */
  37. public function testHandle(): void
  38. {
  39. $request = ServerRequestFactory::fromGlobals(['REQUEST_URI' => '/cakes']);
  40. $request = $request->withAttribute('params', [
  41. 'controller' => 'Cakes',
  42. 'action' => 'index',
  43. 'plugin' => null,
  44. 'pass' => [],
  45. ]);
  46. $app = $this->getMockForAbstractClass(MiddlewareApplication::class);
  47. $result = $app->handle($request);
  48. $this->assertInstanceOf(ResponseInterface::class, $result);
  49. $this->assertSame('Not found', '' . $result->getBody());
  50. $this->assertSame(404, $result->getStatusCode());
  51. }
  52. }