ResponsableTest.php 833 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace Illuminate\Tests\Integration\Routing;
  3. use Illuminate\Contracts\Support\Responsable;
  4. use Illuminate\Support\Facades\Route;
  5. use Orchestra\Testbench\TestCase;
  6. class ResponsableTest extends TestCase
  7. {
  8. public function testResponsableObjectsAreRendered()
  9. {
  10. Route::get('/responsable', function () {
  11. return new TestResponsableResponse;
  12. });
  13. $response = $this->get('/responsable');
  14. $this->assertEquals(201, $response->status());
  15. $this->assertSame('Taylor', $response->headers->get('X-Test-Header'));
  16. $this->assertSame('hello world', $response->getContent());
  17. }
  18. }
  19. class TestResponsableResponse implements Responsable
  20. {
  21. public function toResponse($request)
  22. {
  23. return response('hello world', 201, ['X-Test-Header' => 'Taylor']);
  24. }
  25. }