laravel base files
This commit is contained in:
28
tests/ApiTestTrait.php
Normal file
28
tests/ApiTestTrait.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
trait ApiTestTrait
|
||||
{
|
||||
public function assertApiResponse(Array $actualData)
|
||||
{
|
||||
$this->assertApiSuccess();
|
||||
|
||||
$response = json_decode($this->response->getContent(), true);
|
||||
$responseData = $response['data'];
|
||||
|
||||
$this->assertNotEmpty($responseData['id']);
|
||||
$this->assertModelData($actualData, $responseData);
|
||||
}
|
||||
|
||||
public function assertApiSuccess()
|
||||
{
|
||||
$this->assertResponseOk();
|
||||
$this->seeJson(['success' => true]);
|
||||
}
|
||||
|
||||
public function assertModelData(Array $actualData, Array $expectedData)
|
||||
{
|
||||
foreach ($actualData as $key => $value) {
|
||||
$this->assertEquals($actualData[$key], $expectedData[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user