From 06274986a413b247139231465a9e368131dedcd2 Mon Sep 17 00:00:00 2001 From: Kevin Chung Date: Tue, 15 Oct 2024 12:26:27 -0700 Subject: [PATCH] Add `getOriginal` mutator test --- .../Unit/Database/Traits/HasMutatorsTest.php | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/Unit/Database/Traits/HasMutatorsTest.php b/tests/Unit/Database/Traits/HasMutatorsTest.php index 26f3343..2d4a50f 100644 --- a/tests/Unit/Database/Traits/HasMutatorsTest.php +++ b/tests/Unit/Database/Traits/HasMutatorsTest.php @@ -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());