From 0d7f723224bafd332580613e33234afb866efe72 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 28 Mar 2024 21:08:03 +0100 Subject: [PATCH] More fixes --- tests/OrmTest.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/OrmTest.php b/tests/OrmTest.php index 998e010..c0b4447 100644 --- a/tests/OrmTest.php +++ b/tests/OrmTest.php @@ -41,6 +41,7 @@ use danog\AsyncOrm\ValueType; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use ReflectionProperty; +use WeakReference; use function Amp\async; use function Amp\ByteStream\buffer; @@ -349,6 +350,32 @@ final class OrmTest extends TestCase $this->assertSame($obj, $orm[321]); $orm->clear(); + unset($obj); + + $obj = new TestObject; + $ref = WeakReference::create($obj); + $orm[123] = $obj; + unset($obj, $orm[123]); + + $this->assertNull($ref->get()); + + $obj = new TestObject; + $ref = WeakReference::create($obj); + $orm = $field->build(); + $orm[123] = $obj; + unset($obj, $orm); + + while (\gc_collect_cycles()); + $this->assertNull($ref->get()); + + $obj = $field->build()[123]; + $obj->savedProp = 123; + $obj->save(); + $this->assertSame($obj->savedProp, 123); + unset($obj); + + $this->assertSame($field->build()[123]->savedProp, 123); + unset($obj, $orm); } public static function provideSettingsKeysValues(): \Generator