Skip to content

Commit

Permalink
Removed 6.x support, and thus no need for handling the differend asse…
Browse files Browse the repository at this point in the history
…rt locations

Co-authored-by: Morten D. Hansen <morten@visia.dk>
  • Loading branch information
erikn69 and MortenDHansen committed Dec 26, 2024
1 parent 2d5f2b1 commit 094fe08
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 46 deletions.
13 changes: 0 additions & 13 deletions tests/AuditingTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}
14 changes: 7 additions & 7 deletions tests/Functional/AuditingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 9 additions & 8 deletions tests/Unit/AuditTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand All @@ -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');
}

/**
Expand All @@ -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(),
Expand Down Expand Up @@ -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',
],
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -490,7 +491,7 @@ public function itReturnsTags()
]);

$this->assertIsArray($audit->getTags());
self::Assert()::assertArraySubset([
Assert::assertArraySubset([
'foo',
'bar',
'baz',
Expand Down
36 changes: 18 additions & 18 deletions tests/Unit/AuditableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -175,7 +175,7 @@ public function itReturnsTheDefaultAuditEvents()
{
$model = new Article();

self::Assert()::assertArraySubset([
Assert::assertArraySubset([
'created',
'updated',
'deleted',
Expand All @@ -196,7 +196,7 @@ public function itReturnsTheCustomAuditEventsFromAttribute()
'archived',
];

self::Assert()::assertArraySubset([
Assert::assertArraySubset([
'published' => 'getPublishedEventAttributes',
'archived',
], $model->getAuditEvents(), true);
Expand All @@ -215,7 +215,7 @@ public function itReturnsTheCustomAuditEventsFromConfig()

$model = new Article();

self::Assert()::assertArraySubset([
Assert::assertArraySubset([
'published' => 'getPublishedEventAttributes',
'archived',
], $model->getAuditEvents(), true);
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -673,7 +673,7 @@ public function itModifiesTheAuditAttributesSuccessfully()
'reviewed' => Base64Encoder::class,
];

self::Assert()::assertArraySubset([
Assert::assertArraySubset([
'old_values' => [
'title' => 'Ho#################',
'content' => '##A',
Expand Down Expand Up @@ -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.',
Expand All @@ -736,7 +736,7 @@ public function itReturnsTheDefaultAttributesToBeIncludedInTheAudit()
{
$model = new Article();

self::Assert()::assertArraySubset([], $model->getAuditInclude(), true);
Assert::assertArraySubset([], $model->getAuditInclude(), true);
}

/**
Expand All @@ -752,7 +752,7 @@ public function itReturnsTheCustomAttributesToBeIncludedInTheAudit()
'content',
];

self::Assert()::assertArraySubset([
Assert::assertArraySubset([
'title',
'content',
], $model->getAuditInclude(), true);
Expand All @@ -766,7 +766,7 @@ public function itReturnsTheDefaultAttributesToBeExcludedFromTheAudit()
{
$model = new Article();

self::Assert()::assertArraySubset([], $model->getAuditExclude(), true);
Assert::assertArraySubset([], $model->getAuditExclude(), true);
}

/**
Expand All @@ -781,7 +781,7 @@ public function itReturnsTheCustomAttributesToBeExcludedFromTheAudit()
'published_at',
];

self::Assert()::assertArraySubset([
Assert::assertArraySubset([
'published_at',
], $model->getAuditExclude(), true);
}
Expand Down Expand Up @@ -962,7 +962,7 @@ public function itReturnsTheDefaultGeneratedAuditTags()
{
$model = new Article();

self::Assert()::assertArraySubset([], $model->generateTags(), true);
Assert::assertArraySubset([], $model->generateTags(), true);
}

/**
Expand All @@ -981,7 +981,7 @@ public function generateTags(): array
}
};

self::Assert()::assertArraySubset([
Assert::assertArraySubset([
'foo',
'bar',
], $model->generateTags(), true);
Expand Down Expand Up @@ -1188,7 +1188,7 @@ public function itFailsToTransitionWhenTheAuditableAttributeCompatibilityIsNotMe
$e->getMessage()
);

self::Assert()::assertArraySubset([
Assert::assertArraySubset([
'subject',
'text',
], $e->getIncompatibilities(), true);
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 094fe08

Please sign in to comment.