clqms-be/tests/feature/Patients/PatientShowTest.php
2025-09-23 10:18:48 +07:00

40 lines
1.1 KiB
PHP

<?php
namespace Tests\Feature\Patient;
use CodeIgniter\Test\FeatureTestTrait;
use CodeIgniter\Test\CIUnitTestCase;
class PatientShowTest extends CIUnitTestCase
{
use FeatureTestTrait;
public function testShowNotFound()
{
$result = $this->call('get', 'api/patient/999999'); // ID yang tidak ada
$result->assertStatus(200);
$json = $result->getJSON(); // bentuk string JSON
$json = json_decode($json, true);
// $this->assertSame('Patient with ID 999999 not found.', $json['message']);
$result->assertJSONFragment([
'status' => 'success',
'data' => []
]);
}
public function testShowFound() {
$result = $this->call('get', 'api/patient/1'); // ID yang tidak ada
$result->assertStatus(200);
$json = $result->getJSON();
$data = json_decode($json, true);
$this->assertEquals('success', $data['status']);
$this->assertNotNull($data['data']); // data tidak null
$this->assertIsArray($data['data']); // data berupa array
}
}