Skip to content

Commit

Permalink
Fix EntityTrait and merging of properties that are not assoc arrays.
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Mar 6, 2017
1 parent defe9fe commit 6a554e0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Datasource/EntityTrait.php
Expand Up @@ -433,7 +433,7 @@ public function setHidden(array $properties, $merge = false)
return $this;
}

$this->_hidden += $properties;
$this->_hidden = array_merge($this->_hidden, $properties);

return $this;
}
Expand Down Expand Up @@ -482,7 +482,7 @@ public function setVirtual(array $properties, $merge = false)
return $this;
}

$this->_virtual += $properties;
$this->_virtual = array_merge($this->_virtual, $properties);

return $this;
}
Expand Down
43 changes: 43 additions & 0 deletions tests/TestCase/ORM/EntityTest.php
Expand Up @@ -1030,6 +1030,49 @@ public function testToArrayHiddenProperties()
$this->assertEquals(['name' => 'mark', 'id' => 1], $entity->toArray());
}

/**
* Tests setting hidden properties.
*
* @return void
*/
public function testSetHidden()
{
$data = ['secret' => 'sauce', 'name' => 'mark', 'id' => 1];
$entity = new Entity($data);
$entity->setVirtual(['secret']);

$result = $entity->getVirtual();
$this->assertSame(['secret'], $result);

$entity->setVirtual(['name']);

$result = $entity->getVirtual();
$this->assertSame(['name'], $result);
}

/**
* Tests setting hidden properties with merging.
*
* @return void
*/
public function testSetHiddenWithMerge()
{
$data = ['secret' => 'sauce', 'name' => 'mark', 'id' => 1];
$entity = new Entity($data);
$entity->setVirtual(['secret']);

$result = $entity->getVirtual();
$this->assertSame(['secret'], $result);

$entity->setVirtual(['name'], true);

$result = $entity->getVirtual();
$this->assertSame(['secret', 'name'], $result);

$entity->setVirtual(['name'], true);
$this->assertSame(['secret', 'name'], $result);
}

/**
* Test toArray includes 'virtual' properties.
*
Expand Down

0 comments on commit 6a554e0

Please sign in to comment.