Skip to content

Commit 247b1dd

Browse files
committed
fix(Entity): Fix magic setter call for custom strong typed setters
Signed-off-by: provokateurin <kate@provokateurin.de>
1 parent 6d6baec commit 247b1dd

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

lib/public/AppFramework/Db/Entity.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ public static function fromRow(array $row): static {
5252
$instance = new static();
5353

5454
foreach ($row as $key => $value) {
55-
$prop = ucfirst($instance->columnToProperty($key));
56-
$setter = 'set' . $prop;
57-
$instance->$setter($value);
55+
$prop = $instance->columnToProperty($key);
56+
$instance->setter($prop, [$value]);
5857
}
5958

6059
$instance->resetUpdatedFields();

tests/lib/AppFramework/Db/EntityTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
* @method void setTrueOrFalse(bool $trueOrFalse)
2828
* @method bool getAnotherBool()
2929
* @method bool isAnotherBool()
30-
* @method void setAnotherBool(bool $anotherBool)
3130
* @method string getLongText()
3231
* @method void setLongText(string $longText)
3332
*/
@@ -47,6 +46,10 @@ public function __construct($name = null) {
4746
$this->addType('longText', 'blob');
4847
$this->name = $name;
4948
}
49+
50+
public function setAnotherBool(bool $anotherBool): void {
51+
parent::setAnotherBool($anotherBool);
52+
}
5053
}
5154

5255

@@ -71,12 +74,14 @@ public function testResetUpdatedFields() {
7174
public function testFromRow() {
7275
$row = [
7376
'pre_name' => 'john',
74-
'email' => 'john@something.com'
77+
'email' => 'john@something.com',
78+
'another_bool' => 1,
7579
];
7680
$this->entity = TestEntity::fromRow($row);
7781

7882
$this->assertEquals($row['pre_name'], $this->entity->getPreName());
7983
$this->assertEquals($row['email'], $this->entity->getEmail());
84+
$this->assertEquals($row['another_bool'], $this->entity->getAnotherBool());
8085
}
8186

8287

0 commit comments

Comments
 (0)