Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Support Responsable objects.
This is the foundation for allowing objects to be converted into full HTTP responses, allowing more fluent API packages to be built in the future.
- Loading branch information
Showing
with
51 additions
and 1 deletion.
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Illuminate\Contracts\Support; | ||
|
||
interface Responsable | ||
{ | ||
/** | ||
* Create an HTTP response that represents the object. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function toResponse(); | ||
} |
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
use Orchestra\Testbench\TestCase; | ||
use Illuminate\Support\Facades\Route; | ||
use Illuminate\Contracts\Support\Responsable; | ||
|
||
/** | ||
* @group integration | ||
*/ | ||
class ResponsableTest extends TestCase | ||
{ | ||
public function test_responsable_objects_are_rendered() | ||
{ | ||
Route::get('/responsable', function () { | ||
return new TestResponsableResponse; | ||
}); | ||
|
||
$response = $this->get('/responsable'); | ||
|
||
$this->assertEquals(201, $response->status()); | ||
$this->assertEquals('Taylor', $response->headers->get('X-Test-Header')); | ||
$this->assertEquals('hello world', $response->getContent()); | ||
} | ||
} | ||
|
||
|
||
class TestResponsableResponse implements Responsable | ||
{ | ||
public function toResponse() | ||
{ | ||
return response('hello world', 201, ['X-Test-Header' => 'Taylor']); | ||
} | ||
} |