aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorprovokateurin <kate@provokateurin.de>2024-09-15 13:40:16 +0200
committerprovokateurin <kate@provokateurin.de>2024-09-15 15:14:54 +0200
commit247b1dd70e4518012bf4a55dea56a349886b7b38 (patch)
tree988ec2ad8351afc3f3f6cd899b9226b0144fcfff
parent6d6baec54f3ebaf3d3917a58aa5281a7a21e738b (diff)
downloadnextcloud-server-fix/entity/strict-types.tar.gz
nextcloud-server-fix/entity/strict-types.zip
fix(Entity): Fix magic setter call for custom strong typed settersfix/entity/strict-types
Signed-off-by: provokateurin <kate@provokateurin.de>
-rw-r--r--lib/public/AppFramework/Db/Entity.php5
-rw-r--r--tests/lib/AppFramework/Db/EntityTest.php9
2 files changed, 9 insertions, 5 deletions
diff --git a/lib/public/AppFramework/Db/Entity.php b/lib/public/AppFramework/Db/Entity.php
index da2a8ab62d8..8a0d3fb140f 100644
--- a/lib/public/AppFramework/Db/Entity.php
+++ b/lib/public/AppFramework/Db/Entity.php
@@ -52,9 +52,8 @@ abstract class Entity {
$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();
diff --git a/tests/lib/AppFramework/Db/EntityTest.php b/tests/lib/AppFramework/Db/EntityTest.php
index a521b480f8f..754c88eb233 100644
--- a/tests/lib/AppFramework/Db/EntityTest.php
+++ b/tests/lib/AppFramework/Db/EntityTest.php
@@ -27,7 +27,6 @@ use PHPUnit\Framework\Constraint\IsType;
* @method void setTrueOrFalse(bool $trueOrFalse)
* @method bool getAnotherBool()
* @method bool isAnotherBool()
- * @method void setAnotherBool(bool $anotherBool)
* @method string getLongText()
* @method void setLongText(string $longText)
*/
@@ -47,6 +46,10 @@ class TestEntity extends Entity {
$this->addType('longText', 'blob');
$this->name = $name;
}
+
+ public function setAnotherBool(bool $anotherBool): void {
+ parent::setAnotherBool($anotherBool);
+ }
}
@@ -71,12 +74,14 @@ class EntityTest extends \Test\TestCase {
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());
}