From 559b391e2ebf46a734b3f82d4f18faf425107054 Mon Sep 17 00:00:00 2001 From: erikn69 Date: Fri, 27 Dec 2024 10:04:04 -0500 Subject: [PATCH] Removed 6.x support, no need for different `assert' locations (#989) Co-authored-by: Morten D. Hansen --- tests/AuditingTestCase.php | 13 ----------- tests/Functional/AuditingTest.php | 14 ++++++------ tests/Unit/AuditTest.php | 17 ++++++++------- tests/Unit/AuditableTest.php | 36 +++++++++++++++---------------- 4 files changed, 34 insertions(+), 46 deletions(-) diff --git a/tests/AuditingTestCase.php b/tests/AuditingTestCase.php index c5565022..c8a5e7dd 100644 --- a/tests/AuditingTestCase.php +++ b/tests/AuditingTestCase.php @@ -66,17 +66,4 @@ protected function getPackageProviders($app) AuditingServiceProvider::class, ]; } - - /** - * Locate the Illuminate testing class. It changed namespace with v7 - * @see https://readouble.com/laravel/7.x/en/upgrade.html - * @return class-string<\Illuminate\Foundation\Testing\Assert|\Illuminate\Testing\Assert> - */ - public static function Assert(): string - { - if (class_exists('Illuminate\Foundation\Testing\Assert')) { - return '\Illuminate\Foundation\Testing\Assert'; - } - return '\Illuminate\Testing\Assert'; - } } diff --git a/tests/Functional/AuditingTest.php b/tests/Functional/AuditingTest.php index 327cd34e..a569f981 100644 --- a/tests/Functional/AuditingTest.php +++ b/tests/Functional/AuditingTest.php @@ -4,10 +4,10 @@ use Carbon\Carbon; use Illuminate\Database\QueryException; -use Illuminate\Foundation\Testing\Assert; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Event; +use Illuminate\Testing\Assert; use InvalidArgumentException; use OwenIt\Auditing\Events\AuditCustom; use OwenIt\Auditing\Events\Audited; @@ -156,7 +156,7 @@ public function itWillAuditTheCreatedEvent() $this->assertEmpty($audit->old_values); - self::Assert()::assertArraySubset([ + Assert::assertArraySubset([ 'title' => 'How To Audit Eloquent Models', 'content' => 'N/A', 'published_at' => null, @@ -193,13 +193,13 @@ public function itWillAuditTheUpdatedEvent() $this->assertNotNull($audit); - self::Assert()::assertArraySubset([ + Assert::assertArraySubset([ 'content' => 'N/A', 'published_at' => null, 'reviewed' => 0, ], $audit->old_values, true); - self::Assert()::assertArraySubset([ + Assert::assertArraySubset([ 'content' => Article::contentMutate('First step: install the laravel-auditing package.'), 'published_at' => $now->toDateTimeString(), 'reviewed' => 1, @@ -228,7 +228,7 @@ public function itWillAuditTheDeletedEvent() $this->assertNotNull($audit); - self::Assert()::assertArraySubset([ + Assert::assertArraySubset([ 'title' => 'How To Audit Eloquent Models', 'content' => 'N/A', 'published_at' => null, @@ -264,7 +264,7 @@ public function itWillAuditTheRestoredEvent() $this->assertEmpty($audit->old_values); - self::Assert()::assertArraySubset([ + Assert::assertArraySubset([ 'title' => 'How To Audit Eloquent Models', 'content' => 'N/A', 'published_at' => null, @@ -373,7 +373,7 @@ public function itWillAuditUsingTheDefaultDriver() $this->assertEmpty($audit->old_values); - self::Assert()::assertArraySubset([ + Assert::assertArraySubset([ 'title' => 'How To Audit Using The Fallback Driver', 'content' => 'N/A', 'published_at' => null, diff --git a/tests/Unit/AuditTest.php b/tests/Unit/AuditTest.php index 203863c3..35362caa 100644 --- a/tests/Unit/AuditTest.php +++ b/tests/Unit/AuditTest.php @@ -4,6 +4,7 @@ use Carbon\Carbon; use DateTimeInterface; +use Illuminate\Testing\Assert; use OwenIt\Auditing\Encoders\Base64Encoder; use OwenIt\Auditing\Models\Audit; use OwenIt\Auditing\Redactors\LeftRedactor; @@ -36,7 +37,7 @@ public function itResolvesAuditData() $resolvedData = $audit->resolveData(); $this->assertCount(15, $resolvedData); - self::Assert()::assertArraySubset([ + Assert::assertArraySubset([ 'audit_id' => 1, 'audit_event' => 'created', 'audit_url' => UrlResolver::resolveCommandLine(), @@ -85,7 +86,7 @@ public function itResolvesAuditDataIncludingUserAttributes() $this->assertCount(21, $resolvedData = $audit->resolveData()); - self::Assert()::assertArraySubset([ + Assert::assertArraySubset([ 'audit_id' => 2, 'audit_event' => 'created', 'audit_url' => UrlResolver::resolveCommandLine(), @@ -203,7 +204,7 @@ public function itReturnsAuditMetadataAsArray() $this->assertCount(10, $metadata = $audit->getMetadata()); - self::Assert()::assertArraySubset([ + Assert::assertArraySubset([ 'audit_id' => 1, 'audit_event' => 'created', 'audit_url' => UrlResolver::resolveCommandLine(), @@ -229,7 +230,7 @@ public function itReturnsProperCommandLineInUrlAuditMetadata() $this->assertNotNull($audit); - self::Assert()::assertEquals($audit->getMetadata()['audit_url'], 'vendor/bin/phpunit tests/Unit/AuditTest.php --group command-line-url-resolver'); + Assert::assertEquals($audit->getMetadata()['audit_url'], 'vendor/bin/phpunit tests/Unit/AuditTest.php --group command-line-url-resolver'); } /** @@ -253,7 +254,7 @@ public function itReturnsAuditMetadataIncludingUserAttributesAsArray() $this->assertCount(16, $metadata = $audit->getMetadata()); - self::Assert()::assertArraySubset([ + Assert::assertArraySubset([ 'audit_id' => 2, 'audit_event' => 'created', 'audit_url' => UrlResolver::resolveCommandLine(), @@ -369,7 +370,7 @@ public function itReturnsAuditableModifiedAttributesAsArray() $this->assertCount(5, $modified = $audit->getModified()); - self::Assert()::assertArraySubset([ + Assert::assertArraySubset([ 'title' => [ 'new' => 'HOW TO AUDIT ELOQUENT MODELS', ], @@ -458,7 +459,7 @@ public function itReturnsDecodedAuditableAttributes() $this->assertCount(3, $modified = $audit->getModified()); - self::Assert()::assertArraySubset([ + Assert::assertArraySubset([ 'title' => [ 'new' => 'HOW TO AUDIT ELOQUENT MODELS', 'old' => 'HOW TO AUDIT MODELS', @@ -490,7 +491,7 @@ public function itReturnsTags() ]); $this->assertIsArray($audit->getTags()); - self::Assert()::assertArraySubset([ + Assert::assertArraySubset([ 'foo', 'bar', 'baz', diff --git a/tests/Unit/AuditableTest.php b/tests/Unit/AuditableTest.php index 611c0194..abe71292 100644 --- a/tests/Unit/AuditableTest.php +++ b/tests/Unit/AuditableTest.php @@ -4,10 +4,10 @@ use Carbon\Carbon; use Illuminate\Database\Eloquent\Relations\Relation; -use Illuminate\Foundation\Testing\Assert; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Support\Facades\App; use Illuminate\Support\Str; +use Illuminate\Testing\Assert; use OwenIt\Auditing\Contracts\Auditable; use OwenIt\Auditing\Encoders\Base64Encoder; use OwenIt\Auditing\Exceptions\AuditableTransitionException; @@ -175,7 +175,7 @@ public function itReturnsTheDefaultAuditEvents() { $model = new Article(); - self::Assert()::assertArraySubset([ + Assert::assertArraySubset([ 'created', 'updated', 'deleted', @@ -196,7 +196,7 @@ public function itReturnsTheCustomAuditEventsFromAttribute() 'archived', ]; - self::Assert()::assertArraySubset([ + Assert::assertArraySubset([ 'published' => 'getPublishedEventAttributes', 'archived', ], $model->getAuditEvents(), true); @@ -215,7 +215,7 @@ public function itReturnsTheCustomAuditEventsFromConfig() $model = new Article(); - self::Assert()::assertArraySubset([ + Assert::assertArraySubset([ 'published' => 'getPublishedEventAttributes', 'archived', ], $model->getAuditEvents(), true); @@ -460,7 +460,7 @@ public function itReturnsTheAuditData() $this->assertCount(11, $auditData = $model->toAudit()); $morphPrefix = config('audit.user.morph_prefix', 'user'); - self::Assert()::assertArraySubset([ + Assert::assertArraySubset([ 'old_values' => [], 'new_values' => [ 'title' => 'How To Audit Eloquent Models', @@ -520,7 +520,7 @@ public function itReturnsTheAuditDataIncludingUserAttributes( $this->assertCount(11, $auditData = $model->toAudit()); $morphPrefix = config('audit.user.morph_prefix', 'user'); - self::Assert()::assertArraySubset([ + Assert::assertArraySubset([ 'old_values' => [], 'new_values' => [ 'title' => 'How To Audit Eloquent Models', @@ -603,7 +603,7 @@ public function itExcludesAttributesFromTheAuditDataWhenInStrictMode() $this->assertCount(11, $auditData = $model->toAudit()); $morphPrefix = config('audit.user.morph_prefix', 'user'); - self::Assert()::assertArraySubset([ + Assert::assertArraySubset([ 'old_values' => [], 'new_values' => [ 'title' => 'How To Audit Eloquent Models', @@ -673,7 +673,7 @@ public function itModifiesTheAuditAttributesSuccessfully() 'reviewed' => Base64Encoder::class, ]; - self::Assert()::assertArraySubset([ + Assert::assertArraySubset([ 'old_values' => [ 'title' => 'Ho#################', 'content' => '##A', @@ -717,7 +717,7 @@ public function transformAudit(array $data): array $this->assertCount(11, $auditData = $model->toAudit()); - self::Assert()::assertArraySubset([ + Assert::assertArraySubset([ 'new_values' => [ 'title' => 'How To Audit Eloquent Models', 'content' => 'First step: install the laravel-auditing package.', @@ -736,7 +736,7 @@ public function itReturnsTheDefaultAttributesToBeIncludedInTheAudit() { $model = new Article(); - self::Assert()::assertArraySubset([], $model->getAuditInclude(), true); + Assert::assertArraySubset([], $model->getAuditInclude(), true); } /** @@ -752,7 +752,7 @@ public function itReturnsTheCustomAttributesToBeIncludedInTheAudit() 'content', ]; - self::Assert()::assertArraySubset([ + Assert::assertArraySubset([ 'title', 'content', ], $model->getAuditInclude(), true); @@ -766,7 +766,7 @@ public function itReturnsTheDefaultAttributesToBeExcludedFromTheAudit() { $model = new Article(); - self::Assert()::assertArraySubset([], $model->getAuditExclude(), true); + Assert::assertArraySubset([], $model->getAuditExclude(), true); } /** @@ -781,7 +781,7 @@ public function itReturnsTheCustomAttributesToBeExcludedFromTheAudit() 'published_at', ]; - self::Assert()::assertArraySubset([ + Assert::assertArraySubset([ 'published_at', ], $model->getAuditExclude(), true); } @@ -962,7 +962,7 @@ public function itReturnsTheDefaultGeneratedAuditTags() { $model = new Article(); - self::Assert()::assertArraySubset([], $model->generateTags(), true); + Assert::assertArraySubset([], $model->generateTags(), true); } /** @@ -981,7 +981,7 @@ public function generateTags(): array } }; - self::Assert()::assertArraySubset([ + Assert::assertArraySubset([ 'foo', 'bar', ], $model->generateTags(), true); @@ -1188,7 +1188,7 @@ public function itFailsToTransitionWhenTheAuditableAttributeCompatibilityIsNotMe $e->getMessage() ); - self::Assert()::assertArraySubset([ + Assert::assertArraySubset([ 'subject', 'text', ], $e->getIncompatibilities(), true); @@ -1402,7 +1402,7 @@ public function itWorksWhenConfigAllowedArrayValueIsTrue() $auditData = $model->toAudit(); $morphPrefix = config('audit.user.morph_prefix', 'user'); - self::Assert()::assertArraySubset([ + Assert::assertArraySubset([ 'old_values' => [], 'new_values' => [ 'title' => 'How To Audit Eloquent Models', @@ -1447,7 +1447,7 @@ public function itWorksWhenConfigAllowedArrayValueIsFalse() $auditData = $model->toAudit(); $morphPrefix = config('audit.user.morph_prefix', 'user'); - self::Assert()::assertArraySubset([ + Assert::assertArraySubset([ 'old_values' => [], 'new_values' => [ 'title' => 'How To Audit Eloquent Models',