A free open source IT asset/license management system
Refactor base test into Trait, clean test output for easier comparison
Brady Wetherington8a5f6d2a5d30
diff --git a/tests/Support/AssertHasActionLogs.php b/tests/Support/AssertHasActionLogs.phpnew file mode 100644index 0000000000..8eebc8d87a--- /dev/null+++ b/tests/Support/AssertHasActionLogs.php@@ -0,0 +1,17 @@+<?php++namespace Tests\Support;++use App\Models\Actionlog;+use Illuminate\Database\Eloquent\Model;+use PHPUnit\Framework\Assert;+use function PHPUnit\Framework\assertEquals;++trait AssertHasActionLogs+{+ public function assertHasTheseActionLogs(Model $item, array $statuses)+ {+ Assert::assertEquals($statuses, $item->assetlog()->orderBy('id')->pluck('action_type')->toArray(), "Failed asserting that action logs match");+ }++}\ No newline at end of filediff --git a/tests/TestCase.php b/tests/TestCase.phpindex 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 BaseTestCaseuse 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++;- }-- }}