Skip to content

Commit

Permalink
Add getOriginal mutator test
Browse files Browse the repository at this point in the history
  • Loading branch information
kchung committed Oct 15, 2024
1 parent 3a8f426 commit 0627498
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tests/Unit/Database/Traits/HasMutatorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,49 @@ public function testUnserializeAttribute()
$this->assertEquals('serialized_attribute', $model->id);
}

public function testGetOriginal()
{
$uuid = 'cf98906e-9074-11e7-9c8e-437b4bab8527';
$mutator = M::mock(MutatorContract::class)
->shouldReceive('get')
->with('test_mutator')
->andReturnSelf()
->once()
->shouldReceive('unserializeAttribute')
->with('unserialized_attribute')
->andReturn('serialized_attribute')
->once()
->getMock();

app()['mutator'] = $mutator;

$model = new SampleModel();
$original = $model->getOriginal();

$this->assertIsArray($original);
$this->assertEquals('serialized_attribute', $original['id']);
}

public function testGetOriginalProperty()
{
$uuid = 'cf98906e-9074-11e7-9c8e-437b4bab8527';
$mutator = M::mock(MutatorContract::class)
->shouldReceive('get')
->with('test_mutator')
->andReturnSelf()
->once()
->shouldReceive('unserializeAttribute')
->with('unserialized_attribute')
->andReturn('serialized_attribute')
->once()
->getMock();

app()['mutator'] = $mutator;

$model = new SampleModel();
$this->assertEquals('serialized_attribute', $model->getOriginal('id'));
}

public function testGetMutators()
{
$this->assertEquals(['id' => 'test_mutator'], (new SampleModel())->getMutators());
Expand Down

0 comments on commit 0627498

Please sign in to comment.