Skip to content

Commit

Permalink
Remove dependency on Laravel's response factory as this is not bound …
Browse files Browse the repository at this point in the history
…in Lumen.

Provide our own response factory, increases indirection but allows us to make this change with minimal changes to tests.
  • Loading branch information
Max Brokman committed Jul 13, 2016
1 parent 97bacaf commit c930597
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/FractalResponseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

use ArrayAccess;
use Closure;
use Illuminate\Contracts\Routing\ResponseFactory;
use Illuminate\Http\Response;
use Illuminate\Pagination\LengthAwarePaginator;
use League\Fractal\Scope;
Expand Down
15 changes: 15 additions & 0 deletions src/ResponseFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php


namespace Vice\LaravelFractal;


use Illuminate\Http\Response;

class ResponseFactory
{
public function make($content = '', $status = 200, array $headers = [])
{
return new Response($content, $status, $headers);
}
}
2 changes: 1 addition & 1 deletion tests/FractalResponseFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace tests\Vice\LaravelFractal;

use Illuminate\Contracts\Routing\ResponseFactory;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use League\Fractal\Manager;
Expand All @@ -12,6 +11,7 @@
use Mockery as m;
use Vice\LaravelFractal\FractalResponseFactory;
use Vice\LaravelFractal\FractalService;
use Vice\LaravelFractal\ResponseFactory;

class FractalResponseFactoryTest extends TestCase
{
Expand Down
23 changes: 23 additions & 0 deletions tests/ResponseFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php


namespace tests\Vice\LaravelFractal;


use Illuminate\Http\Response;
use Vice\LaravelFractal\ResponseFactory;

class ResponseFactoryTest extends TestCase
{
public function testProducesAResponse()
{
$factory = new ResponseFactory();
$response = $factory->make(['foo' => 'bar'], 200, ['header' => 'content']);

$this->assertInstanceOf(Response::class, $response);
$this->assertEquals(['foo' => 'bar'], $response->getOriginalContent());
$this->assertEquals(200, $response->getStatusCode());
$this->assertArrayHasKey('header', $response->headers->all());
$this->assertEquals('content', $response->headers->get('header'));
}
}

0 comments on commit c930597

Please sign in to comment.