Skip to content

Commit

Permalink
Update test to cover new mutator functionality
Browse files Browse the repository at this point in the history
- Extended the itResolvesAuditData, itResolvesAuditDataIncludingUserAttributes, itReturnsTheAppropriateAuditableDataValues, itReturnsAuditableModifiedAttributesAsArray, itReturnsAuditableModifiedAttributesAsJsonString, to validate the behavior of attribute mutator.
- Add content mutator in Article model
  • Loading branch information
hamedghaderi committed Aug 22, 2023
1 parent 1355eec commit 5851ed3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
14 changes: 14 additions & 0 deletions tests/Models/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace OwenIt\Auditing\Tests\Models;

use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use OwenIt\Auditing\Contracts\Auditable;
Expand Down Expand Up @@ -62,4 +63,17 @@ public function getTitleAttribute(string $value): string
{
return strtoupper($value);
}

/**
* Uppercase Content accessor.
*
* @return Attribute
*/
public function content(): Attribute
{
return new Attribute(
get: fn ($value) => $value,
set: fn ($value) => ucwords($value),
);
}
}
10 changes: 5 additions & 5 deletions tests/Unit/AuditTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function itResolvesAuditData()
'user_id' => null,
'user_type' => null,
'new_title' => 'How To Audit Eloquent Models',
'new_content' => 'First step: install the laravel-auditing package.',
'new_content' => 'First Step: Install The Laravel-auditing Package.',
'new_published_at' => $now->toDateTimeString(),
'new_reviewed' => 1,
'new_id' => 1,
Expand Down Expand Up @@ -95,7 +95,7 @@ public function itResolvesAuditDataIncludingUserAttributes()
'user_created_at' => $user->created_at->toDateTimeString(),
'user_updated_at' => $user->updated_at->toDateTimeString(),
'new_title' => 'How To Audit Eloquent Models',
'new_content' => 'First step: install the laravel-auditing package.',
'new_content' => 'First Step: Install The Laravel-auditing Package.',
'new_published_at' => $now->toDateTimeString(),
'new_reviewed' => 1,
'new_id' => 1,
Expand Down Expand Up @@ -141,7 +141,7 @@ public function itReturnsTheAppropriateAuditableDataValues()
$this->assertInstanceOf(DateTimeInterface::class, $audit->getDataValue('new_published_at'));

// Original value
$this->assertSame('First step: install the laravel-auditing package.', $audit->getDataValue('new_content'));
$this->assertSame('First Step: Install The Laravel-auditing Package.', $audit->getDataValue('new_content'));
$this->assertSame('Sanchez', $audit->getDataValue('user_last_name'));

// Invalid value
Expand Down Expand Up @@ -307,7 +307,7 @@ public function itReturnsAuditableModifiedAttributesAsArray()
'new' => 'HOW TO AUDIT ELOQUENT MODELS',
],
'content' => [
'new' => 'First step: install the laravel-auditing package.',
'new' => 'First Step: Install The Laravel-auditing Package.',
],
'published_at' => [
'new' => $audit->getSerializedDate($now),
Expand Down Expand Up @@ -345,7 +345,7 @@ public function itReturnsAuditableModifiedAttributesAsJsonString()
"new" => "HOW TO AUDIT ELOQUENT MODELS"
],
"content" => [
"new" => "First step: install the laravel-auditing package."
"new" => "First Step: Install The Laravel-auditing Package."
],
"published_at" => [
"new" => "$serializedDate"
Expand Down

0 comments on commit 5851ed3

Please sign in to comment.