Skip to content

Commit

Permalink
🚨 first is actually nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
willpower232 committed Dec 24, 2024
1 parent 42e5ed0 commit caae912
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
22 changes: 21 additions & 1 deletion tests/Functional/AuditingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ public function itWillAuditTheRetrievedEvent()

$audit = Audit::first();

$this->assertNotNull($audit);

$this->assertEmpty($audit->old_values);

$this->assertEmpty($audit->new_values);
Expand All @@ -147,6 +149,8 @@ public function itWillAuditTheCreatedEvent()

$audit = Audit::first();

$this->assertNotNull($audit);

$this->assertEmpty($audit->old_values);

Assert::assertArraySubset([
Expand Down Expand Up @@ -184,6 +188,8 @@ public function itWillAuditTheUpdatedEvent()

$audit = Audit::first();

$this->assertNotNull($audit);

Assert::assertArraySubset([
'content' => 'N/A',
'published_at' => null,
Expand Down Expand Up @@ -217,6 +223,8 @@ public function itWillAuditTheDeletedEvent()

$audit = Audit::first();

$this->assertNotNull($audit);

Assert::assertArraySubset([
'title' => 'How To Audit Eloquent Models',
'content' => 'N/A',
Expand Down Expand Up @@ -249,6 +257,8 @@ public function itWillAuditTheRestoredEvent()

$audit = Audit::first();

$this->assertNotNull($audit);

$this->assertEmpty($audit->old_values);

Assert::assertArraySubset([
Expand Down Expand Up @@ -349,6 +359,8 @@ public function itWillAuditUsingTheDefaultDriver()

$audit = Audit::first();

$this->assertNotNull($audit);

$this->assertEmpty($audit->old_values);

Assert::assertArraySubset([
Expand Down Expand Up @@ -444,8 +456,10 @@ public function itHandlesJsonColumnsCorrectly()
$article->config = ['articleIsGood' => false, 'authorsJob' => 'vampire'];
$article->save();

/** @var Audit $audit */
$audit = $article->audits()->skip(1)->first();

$this->assertNotNull($audit);

$this->assertSame(false, $audit->getModified()['config']['new']['articleIsGood']);
$this->assertSame(true, $audit->getModified()['config']['old']['articleIsGood']);
}
Expand All @@ -464,6 +478,9 @@ public function canAddAdditionalResolver()

$this->assertTrue(true);
$audit = $article->audits()->first();

$this->assertNotNull($audit);

$this->assertSame(1, (int) $audit->tenant_id);
}

Expand All @@ -480,6 +497,9 @@ public function canDisableResolver()
$article = Article::factory()->create();

$audit = $article->audits()->first();

$this->assertNotNull($audit);

$this->assertEmpty($audit->ip_address);
}

Expand Down
24 changes: 21 additions & 3 deletions tests/Unit/AuditTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ public function itResolvesAuditData()
'published_at' => $now,
]);

/** @var Audit $audit */
$audit = $article->audits()->first();

$this->assertNotNull($audit);

$resolvedData = $audit->resolveData();
$this->assertCount(15, $resolvedData);

Expand Down Expand Up @@ -83,6 +85,8 @@ public function itResolvesAuditDataIncludingUserAttributes()

$audit = $article->audits()->first();

$this->assertNotNull($audit);

$this->assertCount(21, $resolvedData = $audit->resolveData());

Assert::assertArraySubset([
Expand Down Expand Up @@ -132,6 +136,8 @@ public function itReturnsTheAppropriateAuditableDataValues()
'published_at' => Carbon::now(),
])->audits()->first();

$this->assertNotNull($audit);

// Resolve data, making it available to the getDataValue() method
$this->assertCount(21, $audit->resolveData());

Expand Down Expand Up @@ -198,6 +204,8 @@ public function itReturnsAuditMetadataAsArray()
{
$audit = Article::factory()->create()->audits()->first();

$this->assertNotNull($audit);

$this->assertCount(10, $metadata = $audit->getMetadata());

Assert::assertArraySubset([
Expand Down Expand Up @@ -225,6 +233,8 @@ public function itReturnsProperCommandLineInUrlAuditMetadata()
{
$audit = factory(Article::class)->create()->audits()->first();

$this->assertNotNull($audit);

self::Assert()::assertEquals($audit->getMetadata()['audit_url'], 'vendor/bin/phpunit tests/Unit/AuditTest.php --group command-line-url-resolver');
}

Expand All @@ -244,9 +254,10 @@ public function itReturnsAuditMetadataIncludingUserAttributesAsArray()

$this->actingAs($user);

/** @var Audit $audit */
$audit = Article::factory()->create()->audits()->first();

$this->assertNotNull($audit);

$this->assertCount(16, $metadata = $audit->getMetadata());

Assert::assertArraySubset([
Expand Down Expand Up @@ -278,6 +289,8 @@ public function itReturnsAuditMetadataAsJsonString()
{
$audit = Article::factory()->create()->audits()->first();

$this->assertNotNull($audit);

$metadata = $audit->getMetadata(true, JSON_PRETTY_PRINT);

$created_at = $audit->getSerializedDate($audit->created_at);
Expand Down Expand Up @@ -316,6 +329,8 @@ public function itReturnsAuditMetadataIncludingUserAttributesAsJsonString()

$audit = Article::factory()->create()->audits()->first();

$this->assertNotNull($audit);

$metadata = $audit->getMetadata(true, JSON_PRETTY_PRINT);

$created_at = $audit->getSerializedDate($audit->created_at);
Expand Down Expand Up @@ -360,6 +375,8 @@ public function itReturnsAuditableModifiedAttributesAsArray()
'published_at' => $now,
])->audits()->first();

$this->assertNotNull($audit);

$this->assertCount(5, $modified = $audit->getModified());

Assert::assertArraySubset([
Expand Down Expand Up @@ -390,14 +407,15 @@ public function itReturnsAuditableModifiedAttributesAsJsonString()
{
$now = Carbon::now()->second(0)->microsecond(0);

/** @var Audit $audit */
$audit = Article::factory()->create([
'title' => 'How To Audit Eloquent Models',
'content' => 'First step: install the laravel-auditing package.',
'reviewed' => 1,
'published_at' => $now,
])->audits()->first();

$this->assertNotNull($audit);

$modified = $audit->getModified(true, JSON_PRETTY_PRINT);

$serializedDate = $audit->getSerializedDate($now);
Expand Down
7 changes: 6 additions & 1 deletion tests/Unit/AuditableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -762,8 +762,10 @@ public function itExcludesAttributesFromExclude()
$model->reviewed = 1;
$model->save();

/** @var Audit $audit */
$audit = Audit::all()->first();

$this->assertNotNull($audit);

$this->assertArrayNotHasKey('title', $audit->getModified());
}

Expand Down Expand Up @@ -1051,6 +1053,9 @@ public function itFailsToTransitionWhenTheAuditAuditableIdDoesNotMatchTheModelId

$firstModel = Article::factory()->create();
$firstAudit = $firstModel->audits()->first();

$this->assertNotNull($firstAudit);

$firstAudit->auditable_id = $firstModel->id;

$secondModel = Article::factory()->create();
Expand Down

0 comments on commit caae912

Please sign in to comment.