Skip to content

Commit

Permalink
Mutators included in array conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
RemiCollin committed Mar 21, 2015
1 parent b5a4c81 commit f4bc1c5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function __set($key, $value)
if($this->hasSetMutator($key))
{
$method = 'set'.$this->getMutatorMethod($key);

$this->$method($value);
}
else $this->attributes[$key] = $value;
Expand Down Expand Up @@ -105,6 +105,11 @@ public function toArray()
{
unset($attributes[$key]);

This comment has been minimized.

Copy link
@thasmo

thasmo Jun 10, 2015

Should add a continue; here to avoid returning hidden attributes which have a get mutator.

}
if($this->hasGetMutator($key))
{
$method = 'get'.$this->getMutatorMethod($key);
$attributes[$key] = $this->$method($attribute);
}
}
return $attributes;
}
Expand Down
7 changes: 6 additions & 1 deletion tests/AnalogueTest/EntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,14 @@ public function testMutators()
$this->assertEquals('mutated_momo_mutated', $res->string);
}

public function testSetMutators()
public function testMutatorsToArray()
{
$res = new Resource('name');
$res->string = 'momo';

$array = $res->toArray();

$this->assertEquals('mutated_momo_mutated', $array['string']);
}

public function testParsingLazyLoadedCollections()
Expand Down

0 comments on commit f4bc1c5

Please sign in to comment.