Skip to content

Commit

Permalink
Merge pull request #508 from spatie/ft-phpunit-issue-507
Browse files Browse the repository at this point in the history
add phpunit test for mutated attribute
  • Loading branch information
Gummibeer authored Apr 5, 2019
2 parents 2e45150 + 0d43d9e commit eedee0f
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/DetectsChangesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,41 @@ public function getDescriptionAttribute()
$this->assertEquals($expectedChanges, $this->getLastActivity()->changes()->toArray());
}

/** @test */
public function it_can_use_mutated_as_loggable_attributes()
{
$userClass = new class() extends User {
protected $fillable = ['name', 'text'];
protected static $logAttributes = ['*'];

use LogsActivity;

public function setNameAttribute($value)
{
$this->attributes['name'] = strtoupper($value);
}
};

Carbon::setTestNow(Carbon::create(2017, 1, 1, 12, 0, 0));
$user = new $userClass();
$user->name = 'my name';
$user->text = 'my text';
$user->save();

$expectedChanges = [
'attributes' => [
'id' => $user->id,
'name' => 'MY NAME',
'text' => 'my text',
'created_at' => '2017-01-01 12:00:00',
'updated_at' => '2017-01-01 12:00:00',
'deleted_at' => null,
],
];

$this->assertEquals($expectedChanges, $this->getLastActivity()->changes()->toArray());
}

protected function createArticle(): Article
{
$article = new $this->article();
Expand Down

0 comments on commit eedee0f

Please sign in to comment.