Skip to content

Commit

Permalink
fix(Entity): Fix magic setter call for custom strong typed setters
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <kate@provokateurin.de>
  • Loading branch information
provokateurin authored and backportbot[bot] committed Sep 16, 2024
1 parent cea10d6 commit b7b5b50
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 2 additions & 3 deletions lib/public/AppFramework/Db/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ public static function fromRow(array $row): static {
$instance = new static();

foreach ($row as $key => $value) {
$prop = ucfirst($instance->columnToProperty($key));
$setter = 'set' . $prop;
$instance->$setter($value);
$prop = $instance->columnToProperty($key);
$instance->setter($prop, [$value]);
}

$instance->resetUpdatedFields();
Expand Down
9 changes: 7 additions & 2 deletions tests/lib/AppFramework/Db/EntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
* @method void setTrueOrFalse(bool $trueOrFalse)
* @method bool getAnotherBool()
* @method bool isAnotherBool()
* @method void setAnotherBool(bool $anotherBool)
* @method string getLongText()
* @method void setLongText(string $longText)
*/
Expand All @@ -47,6 +46,10 @@ public function __construct($name = null) {
$this->addType('longText', 'blob');
$this->name = $name;
}

public function setAnotherBool(bool $anotherBool): void {
parent::setAnotherBool($anotherBool);
}
}


Expand All @@ -71,12 +74,14 @@ public function testResetUpdatedFields() {
public function testFromRow() {
$row = [
'pre_name' => 'john',
'email' => 'john@something.com'
'email' => 'john@something.com',
'another_bool' => 1,
];
$this->entity = TestEntity::fromRow($row);

$this->assertEquals($row['pre_name'], $this->entity->getPreName());
$this->assertEquals($row['email'], $this->entity->getEmail());
$this->assertEquals($row['another_bool'], $this->entity->getAnotherBool());
}


Expand Down

0 comments on commit b7b5b50

Please sign in to comment.