Skip to content

Commit

Permalink
Consider mutators on __isset of Attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorbari authored and gmsantos committed Sep 20, 2017
1 parent a43eee2 commit 7548292
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Mongolid/Model/Attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public function __set($key, $value)
*/
public function __isset($key)
{
return isset($this->attributes[$key]);
return !is_null($this->{$key});
}

/**
Expand Down
20 changes: 20 additions & 0 deletions tests/Mongolid/Model/AttributesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,26 @@ public function testShouldCheckIfAttributeIsSet()
$this->assertFalse(isset($model->nonexistant));
}

public function testShouldCheckIfMutatedAttributeIsSet()
{
// Arrange
$model = new class() {
use Attributes;

public function getNameAttribute()
{
return 'John';
}
};

/* Enable mutator methods */
$model->mutable = true;

// Assert
$this->assertTrue(isset($model->name));
$this->assertFalse(isset($model->nonexistant));
}

public function testShouldUnsetAttributes()
{
// Arrange
Expand Down

0 comments on commit 7548292

Please sign in to comment.