1010use Dingo \Api \Http \Response ;
1111use Dingo \Api \Routing \Router ;
1212use PHPUnit_Framework_TestCase ;
13+ use Dingo \Api \Tests \Stubs \UserStub ;
1314use Illuminate \Container \Container ;
1415use Illuminate \Filesystem \Filesystem ;
1516use Dingo \Api \Tests \Stubs \MiddlewareStub ;
17+ use Dingo \Api \Tests \Stubs \TransformerStub ;
1618use Dingo \Api \Tests \Stubs \RoutingAdapterStub ;
19+ use Dingo \Api \Tests \Stubs \UserTransformerStub ;
1720use Dingo \Api \Exception \InternalHttpException ;
21+ use Dingo \Api \Transformer \Factory as TransformerFactory ;
1822use Illuminate \Support \Facades \Request as RequestFacade ;
1923
2024class DispatcherTest extends PHPUnit_Framework_TestCase
@@ -26,6 +30,8 @@ public function setUp()
2630 $ this ->container ['api.auth ' ] = new MiddlewareStub ;
2731 $ this ->container ['api.limiting ' ] = new MiddlewareStub ;
2832
33+ $ this ->transformerFactory = new TransformerFactory ($ this ->container , new TransformerStub );
34+
2935 $ this ->adapter = new RoutingAdapterStub ;
3036 $ this ->exception = m::mock ('Dingo\Api\Exception\Handler ' );
3137 $ this ->router = new Router ($ this ->adapter , new Http \Parser \Accept ('api ' , 'v1 ' , 'json ' ), $ this ->exception , $ this ->container , null , null );
@@ -38,6 +44,7 @@ public function setUp()
3844 $ this ->dispatcher ->setDefaultFormat ('json ' );
3945
4046 Http \Response::setFormatters (['json ' => new Http \Response \Format \Json ]);
47+ Http \Response::setTransformer ($ this ->transformerFactory );
4148 }
4249
4350 public function tearDown ()
@@ -321,6 +328,25 @@ public function testRequestingRawResponse()
321328 $ this ->assertEquals (['foo ' => 'bar ' ], $ response ->getOriginalContent ());
322329 }
323330
331+ public function testRequestingRawResponseWithTransformers ()
332+ {
333+ $ instance = null ;
334+
335+ $ this ->router ->version ('v1 ' , function () use (&$ instance ) {
336+ $ this ->router ->get ('foo ' , function () use (&$ instance ) {
337+ return $ instance = new UserStub ('Jason ' );
338+ });
339+ });
340+
341+ $ this ->transformerFactory ->register (UserStub::class, UserTransformerStub::class);
342+
343+ $ response = $ this ->dispatcher ->raw ()->get ('foo ' );
344+
345+ $ this ->assertInstanceOf ('Dingo\Api\Http\Response ' , $ response );
346+ $ this ->assertEquals ('{"name":"Jason"} ' , $ response ->getContent ());
347+ $ this ->assertEquals ($ instance , $ response ->getOriginalContent ());
348+ }
349+
324350 public function testUsingRequestFacadeDoesNotCacheRequestInstance ()
325351 {
326352 RequestFacade::setFacadeApplication ($ this ->container );
0 commit comments