Skip to content

Commit

Permalink
Adding test coverage for returning an item or collection without a re…
Browse files Browse the repository at this point in the history
…source key.
  • Loading branch information
joshforbes committed Jun 25, 2016
1 parent b22932c commit a9d8e59
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions tests/Integration/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,23 @@ public function it_can_respond_with_a_single_item()
$this->assertEquals($expectedArray, $array);
}

/**
* @test
*/
public function it_can_respond_with_a_single_item_at_the_top_level()
{
$respondWithItem = $this->getMethod('respondWithItem');
$testController = new TestController();

$response = $respondWithItem->invokeArgs($testController, [$this->testBooks[0], new TestTransformer(), false]);
$array = json_decode(json_encode($response->getData()), true);

$expectedArray = [
'id' => 1, 'author' => 'Philip K Dick', ];

$this->assertEquals($expectedArray, $array);
}

/**
* @test
*/
Expand Down Expand Up @@ -122,15 +139,38 @@ public function it_can_respond_with_a_collection()
$respondWithCollection = $this->getMethod('respondWithCollection');
$testController = new TestController();

$expectedData = [
['id' => 1, 'author' => 'Philip K Dick'],
['id' => 2, 'author' => 'George R. R. Satan'],
];

$response = $respondWithCollection->invokeArgs($testController, [$this->testBooks, new TestTransformer()]);
$array = json_decode(json_encode($response->getData()), true);

$expectedArray = ['data' => [
$this->assertEquals(['data' => $expectedData], $array);
}

/**
* @test
*/
public function it_can_respond_with_a_collection_as_a_top_level_item()
{
$respondWithCollection = $this->getMethod('respondWithCollection');
$testController = new TestController();

$expectedData = [
['id' => 1, 'author' => 'Philip K Dick'],
['id' => 2, 'author' => 'George R. R. Satan'],
]];
];

$this->assertEquals($expectedArray, $array);
$response = $respondWithCollection->invokeArgs($testController, [
$this->testBooks,
new TestTransformer(),
false
]);
$array = json_decode(json_encode($response->getData()), true);

$this->assertEquals($expectedData, $array);
}

/**
Expand Down

0 comments on commit a9d8e59

Please sign in to comment.