From fd54281ce36dc6f9ee01793e2aa27f0ef9d04638 Mon Sep 17 00:00:00 2001 From: Gregory Letellier Date: Tue, 7 Nov 2023 10:36:01 +0100 Subject: [PATCH] =?UTF-8?q?la=20m=C3=A9thode=20find=20de=20l'objet=20retou?= =?UTF-8?q?rne=20l'objet=20lui=20m=C3=AAme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Model.php | 9 ++++----- tests/DbTest.php | 5 ++++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Model.php b/src/Model.php index c800bcf..f0ced76 100644 --- a/src/Model.php +++ b/src/Model.php @@ -66,16 +66,15 @@ class Model return $this; } - public function find(mixed $key): bool - { - $res = false; + public function find(mixed $key): mixed + { $qb = $this->newQueryBuilder(); $find = $qb->find($key); if ($find !== null) { $this->fillData($find->getValues()); - $res = true; + return $this; } - return $res; + return null; } public function save(): bool diff --git a/tests/DbTest.php b/tests/DbTest.php index 375e239..0d45035 100644 --- a/tests/DbTest.php +++ b/tests/DbTest.php @@ -40,9 +40,12 @@ test("model find", function() { $row->setTable("test"); $res = $row->find(1); - expect($res)->toBe(true); + expect($res->id)->toBe(1); expect($row->col1)->toBe("test"); + $res = $row->find(15); + expect($res)->toBe(null); + $row->col1 = "test2"; $res = $row->save(); expect($res)->toBe(true);