Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
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
1 parent
ba6cc92
commit c0c89fd
Showing
4 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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']); | ||
} | ||
} |