Skip to content

Commit 0627498

Browse files
committed
Add getOriginal mutator test
1 parent 3a8f426 commit 0627498

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/Unit/Database/Traits/HasMutatorsTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,49 @@ public function testUnserializeAttribute()
5252
$this->assertEquals('serialized_attribute', $model->id);
5353
}
5454

55+
public function testGetOriginal()
56+
{
57+
$uuid = 'cf98906e-9074-11e7-9c8e-437b4bab8527';
58+
$mutator = M::mock(MutatorContract::class)
59+
->shouldReceive('get')
60+
->with('test_mutator')
61+
->andReturnSelf()
62+
->once()
63+
->shouldReceive('unserializeAttribute')
64+
->with('unserialized_attribute')
65+
->andReturn('serialized_attribute')
66+
->once()
67+
->getMock();
68+
69+
app()['mutator'] = $mutator;
70+
71+
$model = new SampleModel();
72+
$original = $model->getOriginal();
73+
74+
$this->assertIsArray($original);
75+
$this->assertEquals('serialized_attribute', $original['id']);
76+
}
77+
78+
public function testGetOriginalProperty()
79+
{
80+
$uuid = 'cf98906e-9074-11e7-9c8e-437b4bab8527';
81+
$mutator = M::mock(MutatorContract::class)
82+
->shouldReceive('get')
83+
->with('test_mutator')
84+
->andReturnSelf()
85+
->once()
86+
->shouldReceive('unserializeAttribute')
87+
->with('unserialized_attribute')
88+
->andReturn('serialized_attribute')
89+
->once()
90+
->getMock();
91+
92+
app()['mutator'] = $mutator;
93+
94+
$model = new SampleModel();
95+
$this->assertEquals('serialized_attribute', $model->getOriginal('id'));
96+
}
97+
5598
public function testGetMutators()
5699
{
57100
$this->assertEquals(['id' => 'test_mutator'], (new SampleModel())->getMutators());

0 commit comments

Comments
 (0)