From 8a5f6d2a5d301b6e084b83b7328af6e0443b3952 Mon Sep 17 00:00:00 2001 From: Brady Wetherington Date: Fri, 18 Jul 2025 13:16:35 +0100 Subject: [PATCH] Refactor base test into Trait, clean test output for easier comparison --- tests/Support/AssertHasActionLogs.php | 17 +++++++++++++++++ tests/TestCase.php | 17 ++--------------- 2 files changed, 19 insertions(+), 15 deletions(-) create mode 100644 tests/Support/AssertHasActionLogs.php diff --git a/tests/Support/AssertHasActionLogs.php b/tests/Support/AssertHasActionLogs.php new file mode 100644 index 0000000000..8eebc8d87a --- /dev/null +++ b/tests/Support/AssertHasActionLogs.php @@ -0,0 +1,17 @@ +assetlog()->orderBy('id')->pluck('action_type')->toArray(), "Failed asserting that action logs match"); + } + +} \ No newline at end of file diff --git a/tests/TestCase.php b/tests/TestCase.php index 0177767e67..d9f848650a 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,13 +3,11 @@ namespace Tests; use App\Http\Middleware\SecurityHeaders; -use App\Models\Actionlog; -use Illuminate\Database\Eloquent\Model; use Illuminate\Foundation\Testing\LazilyRefreshDatabase; use Illuminate\Foundation\Testing\TestCase as BaseTestCase; -use PHPUnit\Framework\Assert; use RuntimeException; use Tests\Support\AssertsAgainstSlackNotifications; +use Tests\Support\AssertHasActionLogs; use Tests\Support\CanSkipTests; use Tests\Support\CustomTestMacros; use Tests\Support\InteractsWithAuthentication; @@ -24,6 +22,7 @@ abstract class TestCase extends BaseTestCase use InteractsWithAuthentication; use InitializesSettings; use LazilyRefreshDatabase; + use AssertHasActionLogs; private array $globallyDisabledMiddleware = [ SecurityHeaders::class, @@ -51,16 +50,4 @@ abstract class TestCase extends BaseTestCase } } - public function assertHasTheseActionLogs(Model $item, array $statuses) - { - \Log::error("Okay, we're running the test macro now?"); - $logs = Actionlog::where(['item_id' => $item->id, 'item_type' => get_class($item)])->orderBy('id')->get(); - Assert::assertEquals(count($statuses), count($logs), "Wrong count of logs expected - expecting " . count($statuses) . ", got " . count($logs)); - $i = 0; - foreach ($statuses as $status) { - Assert::assertEquals($status, $logs[$i]->action_type, "Unexpected action type - " . $logs[$i]->action_type . " - expecting $status"); - $i++; - } - - } }