phpvms/tests/ApiTestTrait.php

29 lines
715 B
PHP
Raw Normal View History

2017-06-09 02:28:26 +08:00
<?php
trait ApiTestTrait
{
2018-08-27 00:40:04 +08:00
public function assertApiResponse(array $actualData)
2017-06-09 02:28:26 +08:00
{
$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]);
}
2018-08-27 00:40:04 +08:00
public function assertModelData(array $actualData, array $expectedData)
2017-06-09 02:28:26 +08:00
{
foreach ($actualData as $key => $value) {
$this->assertEquals($actualData[$key], $expectedData[$key]);
}
}
2018-08-27 00:40:04 +08:00
}