added test for tebus AT and P and added P
This commit is contained in:
+42
-1
@@ -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.");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user