Skip to content

Commit

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

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

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

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

return $this;
}
Expand Down
11 changes: 6 additions & 5 deletions tests/TestCase/ORM/EntityTest.php
Expand Up @@ -1110,20 +1110,21 @@ public function testToArrayVirtualProperties()
*/
public function testSetVirtualWithMerge()
{
$data = ['secret' => 'sauce', 'name' => 'mark', 'id' => 1];
$data = ['virtual' => 'sauce', 'name' => 'mark', 'id' => 1];
$entity = new Entity($data);
$entity->setVirtual(['secret']);
$entity->setVirtual(['virtual']);

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

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

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

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

/**
Expand Down

0 comments on commit ce40943

Please sign in to comment.