Skip to content

Commit

Permalink
Merge pull request #48008 from nextcloud/fix/entity/strict-types
Browse files Browse the repository at this point in the history
  • Loading branch information
provokateurin authored Sep 16, 2024
2 parents 1a972d0 + 247b1dd commit 8a32881
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 @@ -54,9 +54,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(): void {
public function testFromRow(): void {
$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 8a32881

Please sign in to comment.