From fc128f0831270ceccd592bca62821fd4fd9fe2f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Pel=C3=AD=C5=A1ek?= Date: Mon, 8 Jul 2024 14:17:50 +0200 Subject: [PATCH] Self referencing entity test --- .../Common/Integration/Case428/CaseTest.php | 50 +++++++++++++++ .../Integration/Case428/Entity/User.php | 14 +++++ .../Common/Integration/Case428/schema.php | 61 +++++++++++++++++++ .../MySQL/Integration/Case428/CaseTest.php | 17 ++++++ .../Postgres/Integration/Case428/CaseTest.php | 17 ++++++ .../Integration/Case428/CaseTest.php | 17 ++++++ .../SQLite/Integration/Case428/CaseTest.php | 17 ++++++ 7 files changed, 193 insertions(+) create mode 100644 tests/ORM/Functional/Driver/Common/Integration/Case428/CaseTest.php create mode 100644 tests/ORM/Functional/Driver/Common/Integration/Case428/Entity/User.php create mode 100644 tests/ORM/Functional/Driver/Common/Integration/Case428/schema.php create mode 100644 tests/ORM/Functional/Driver/MySQL/Integration/Case428/CaseTest.php create mode 100644 tests/ORM/Functional/Driver/Postgres/Integration/Case428/CaseTest.php create mode 100644 tests/ORM/Functional/Driver/SQLServer/Integration/Case428/CaseTest.php create mode 100644 tests/ORM/Functional/Driver/SQLite/Integration/Case428/CaseTest.php diff --git a/tests/ORM/Functional/Driver/Common/Integration/Case428/CaseTest.php b/tests/ORM/Functional/Driver/Common/Integration/Case428/CaseTest.php new file mode 100644 index 00000000..892c2c9c --- /dev/null +++ b/tests/ORM/Functional/Driver/Common/Integration/Case428/CaseTest.php @@ -0,0 +1,50 @@ +makeTables(); + + $this->loadSchema(__DIR__ . '/schema.php'); + } + + public function testSave(): void + { + $this->captureWriteQueries(); + $em = new EntityManager($this->orm); + + $user = new User(); + + $em->persist($user); + $em->run(); + + // Check write queries count + $this->assertNumWrites(1); + } + + private function makeTables(): void + { + // Make tables + $this->makeTable(User::ROLE, [ + 'id' => 'primary', // autoincrement + 'user_id' => 'int', + ]); + $this->makeFK(User::ROLE, 'user_id', User::ROLE, 'id', 'CASCADE', 'CASCADE'); + } +} diff --git a/tests/ORM/Functional/Driver/Common/Integration/Case428/Entity/User.php b/tests/ORM/Functional/Driver/Common/Integration/Case428/Entity/User.php new file mode 100644 index 00000000..6942e4c0 --- /dev/null +++ b/tests/ORM/Functional/Driver/Common/Integration/Case428/Entity/User.php @@ -0,0 +1,14 @@ + [ + Schema::ENTITY => User::class, + Schema::SOURCE => Source::class, + Schema::MAPPER => Mapper::class, + Schema::REPOSITORY => Repository::class, + Schema::DATABASE => 'default', + Schema::TABLE => 'user', + Schema::PRIMARY_KEY => ['id'], + Schema::FIND_BY_KEYS => ['id'], + Schema::COLUMNS => [ + 'id' => 'id', + 'user_id' => 'user_id', + ], + Schema::RELATIONS => [ + 'user' => [ + Relation::TYPE => Relation::BELONGS_TO, + Relation::TARGET => 'user', + Relation::LOAD => Relation::LOAD_PROMISE, + Relation::SCHEMA => [ + Relation::CASCADE => true, + Relation::NULLABLE => true, + Relation::INNER_KEY => 'user_id', + Relation::OUTER_KEY => ['id'], + Relation::INVERSION => 'users', + ], + ], + 'users' => [ + Relation::TYPE => Relation::HAS_MANY, + Relation::TARGET => 'user', + Relation::LOAD => Relation::LOAD_PROMISE, + Relation::SCHEMA => [ + Relation::CASCADE => true, + Relation::NULLABLE => false, + Relation::WHERE => [], + Relation::ORDER_BY => [], + Relation::INNER_KEY => ['id'], + Relation::OUTER_KEY => 'user_id', + Relation::INVERSION => 'user', + ], + ], + ], + Schema::SCOPE => null, + Schema::TYPECAST => [ + 'id' => 'int', + 'user_id' => 'int', + ], + Schema::SCHEMA => [], + ], +]; diff --git a/tests/ORM/Functional/Driver/MySQL/Integration/Case428/CaseTest.php b/tests/ORM/Functional/Driver/MySQL/Integration/Case428/CaseTest.php new file mode 100644 index 00000000..854c70ec --- /dev/null +++ b/tests/ORM/Functional/Driver/MySQL/Integration/Case428/CaseTest.php @@ -0,0 +1,17 @@ +