added test for tebus AT and P and added P

This commit is contained in:
hafifierahman
2024-11-25 01:31:05 +08:00
parent 3f4d0412df
commit 51aaa20078
9 changed files with 407 additions and 103 deletions
+42 -1
View File
@@ -1,7 +1,8 @@
<?php
use Laravel\Lumen\Testing\TestCase as BaseTestCase;
use Illuminate\Support\Facades\DB;
use PHPUnit\Framework\Assert as PHPUnit;
abstract class TestCase extends BaseTestCase
{
/**
@@ -13,4 +14,44 @@ abstract class TestCase extends BaseTestCase
{
return require __DIR__.'/../bootstrap/app.php';
}
protected function assertDatabaseHasThroughNorujukan(string $table, array $data, string $connection = null): void
{
$query = DB::connection($connection)->table($table);
foreach ($data as $key => $value) {
$query->where($key, $value);
}
$record = $query->first();
if (!$record) {
// Check if a record exists but doesn't match the expected attributes
$actualRecord = DB::connection($connection)->table($table)->where('norujukan', $data['norujukan'])->first();
if ($actualRecord) {
$mismatchedColumns = [];
foreach ($data as $key => $value) {
if ($actualRecord->$key !== $value) {
$expectedValue = stripslashes($value); // Remove backslashes from expected
$mismatchedColumns[$key] = [
'expected' => $expectedValue,
'actual' => $actualRecord->$key,
];
}
}
PHPUnit::fail(
"A record exists in the table [{$table}] but does not match the expected attributes. " .
"Mismatched columns: " . json_encode($mismatchedColumns)
);
}
PHPUnit::fail(
"Failed asserting that a record exists in the table [{$table}] with the attributes " . json_encode($data)
);
}
PHPUnit::assertNotNull($record, "Record exists and matches the expected attributes.");
}
}