Skip to content

Commit

Permalink
Merge pull request #71 from davitbek/master
Browse files Browse the repository at this point in the history
I have created this PR for #69 (comment) with tests
  • Loading branch information
freekmurze authored Sep 16, 2020
2 parents c4a02a0 + 606acc9 commit d6fca92
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/SchemalessAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ public function __set($name, $value)
$this->set($name, $value);
}

public function __isset($name)
{
$property = $this->get($name);

return isset($property);
}

public function __empty($name)
{
$property = $this->get($name);

return empty($property);
}

/**
* @see Collection::get()
*
Expand Down
20 changes: 20 additions & 0 deletions tests/HasSchemalessAttributesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,26 @@ public function schemaless_attributes_will_get_saved_with_the_model()
$this->assertEquals('value', $this->testModel->schemaless_attributes->name);
}

/** @test */
public function checking_existing_schemaless_attribute_is_empty_with_direct_access()
{
$this->testModel->schemaless_attributes->name = 'value';
$this->testModel->save();

$this->assertFalse(empty($this->testModel->schemaless_attributes->name));
$this->assertTrue(empty($this->testModel->schemaless_attributes->first_name));
}

/** @test */
public function checking_existing_schemaless_attribute_is_empty_with_access_via_get()
{
$this->testModel->schemaless_attributes->name = 'value';
$this->testModel->save();

$this->assertFalse(empty($this->testModel->schemaless_attributes->get('name')));
$this->assertTrue(empty($this->testModel->schemaless_attributes->get('first_name')));
}

/** @test */
public function it_can_handle_an_array()
{
Expand Down

0 comments on commit d6fca92

Please sign in to comment.