From 21898ccb386b8d8e2de56e799283b50bc85ea496 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Thu, 8 Feb 2024 21:34:16 +0400 Subject: [PATCH] Add more tests --- src/Command/Database/Insert.php | 3 +- src/Heap/State.php | 4 +- .../Common/Integration/Case321/CaseTest.php | 33 +++++++++++++++ .../Integration/Case321/Entity/User3.php | 10 +++++ .../Integration/Case321/Entity/User4.php | 11 +++++ .../Common/Integration/Case321/schema.php | 40 +++++++++++++++++++ 6 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 tests/ORM/Functional/Driver/Common/Integration/Case321/Entity/User3.php create mode 100644 tests/ORM/Functional/Driver/Common/Integration/Case321/Entity/User4.php diff --git a/src/Command/Database/Insert.php b/src/Command/Database/Insert.php index 53a1812e..2e3fe6b5 100644 --- a/src/Command/Database/Insert.php +++ b/src/Command/Database/Insert.php @@ -141,7 +141,6 @@ public function execute(): void } } - $state->updateTransactionData(); parent::execute(); @@ -173,6 +172,6 @@ private function hasGeneratedFields(): bool } } - return true; + return false; } } diff --git a/src/Heap/State.php b/src/Heap/State.php index 743da993..05338e6c 100644 --- a/src/Heap/State.php +++ b/src/Heap/State.php @@ -163,7 +163,7 @@ public function getChanges(): array public function getValue(string $key): mixed { - return array_key_exists($key, $this->data) ? $this->data[$key] : ($this->transactionData[$key] ?? null); + return \array_key_exists($key, $this->data) ? $this->data[$key] : ($this->transactionData[$key] ?? null); } public function hasValue(string $key, bool $allowNull = true): bool @@ -171,7 +171,7 @@ public function hasValue(string $key, bool $allowNull = true): bool if (!$allowNull) { return isset($this->data[$key]) || isset($this->transactionData[$key]); } - return array_key_exists($key, $this->data) || array_key_exists($key, $this->transactionData); + return \array_key_exists($key, $this->data) || \array_key_exists($key, $this->transactionData); } public function register(string $key, mixed $value): void diff --git a/tests/ORM/Functional/Driver/Common/Integration/Case321/CaseTest.php b/tests/ORM/Functional/Driver/Common/Integration/Case321/CaseTest.php index dab22c65..9f72f672 100644 --- a/tests/ORM/Functional/Driver/Common/Integration/Case321/CaseTest.php +++ b/tests/ORM/Functional/Driver/Common/Integration/Case321/CaseTest.php @@ -46,6 +46,29 @@ public function test2(): void $this->assertNumWrites(1); } + public function test3(): void + { + $user = new Entity\User3(); + + $this->captureWriteQueries(); + $this->save($user); + + // ORM won't detect any values to store + // because the id field isn't marked as autogenerated + $this->assertNumWrites(0); + } + + public function test4(): void + { + $user = new Entity\User4(); + + $this->save($user); + + // ORM won't detect any values to store + // because the id field isn't marked as autogenerated + $this->assertNumWrites(0); + } + private function makeTables(): void { // Make tables @@ -56,5 +79,15 @@ private function makeTables(): void $this->makeTable('user2', [ 'id' => 'primary', // autoincrement ]); + + $this->makeTable('user3', [ + 'id' => 'primary', // autoincrement + ]); + + $this->logger->display(); + $this->makeTable('user4', [ + 'id' => 'primary', + 'counter' => 'int', + ]); } } diff --git a/tests/ORM/Functional/Driver/Common/Integration/Case321/Entity/User3.php b/tests/ORM/Functional/Driver/Common/Integration/Case321/Entity/User3.php new file mode 100644 index 00000000..a064d589 --- /dev/null +++ b/tests/ORM/Functional/Driver/Common/Integration/Case321/Entity/User3.php @@ -0,0 +1,10 @@ + [ @@ -52,4 +54,42 @@ 'id' => GeneratedField::ON_INSERT, // autoincrement ], ], + 'user3' => [ + Schema::ENTITY => User3::class, + Schema::MAPPER => Mapper::class, + Schema::SOURCE => Source::class, + Schema::DATABASE => 'default', + Schema::TABLE => 'user3', + Schema::PRIMARY_KEY => ['id'], + Schema::FIND_BY_KEYS => ['id'], + Schema::COLUMNS => [ + 'id' => 'id', + ], + Schema::RELATIONS => [], + Schema::SCOPE => null, + Schema::TYPECAST => [ + 'id' => 'int', + ], + Schema::SCHEMA => [], + Schema::GENERATED_FIELDS => [], + ], + 'user4' => [ + Schema::ENTITY => User4::class, + Schema::MAPPER => Mapper::class, + Schema::SOURCE => Source::class, + Schema::DATABASE => 'default', + Schema::TABLE => 'user4', + Schema::PRIMARY_KEY => ['id'], + Schema::COLUMNS => [ + 'id' => 'id', + 'counter' => 'counter', + ], + Schema::TYPECAST => [ + 'id' => 'int', + 'counter' => 'counter', + ], + Schema::GENERATED_FIELDS => [ + 'counter' => GeneratedField::BEFORE_UPDATE, + ], + ], ];