From 1232aea45309cba2d91a6968472f858c6182901d Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Thu, 1 Feb 2024 00:54:38 +0400 Subject: [PATCH] Add a test case --- composer.json | 2 +- .../Driver/Postgres/SerialColumnTest.php | 73 +++++++++++++++++++ tests/bootstrap.php | 13 +++- 3 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 tests/ORM/Functional/Driver/Postgres/SerialColumnTest.php diff --git a/composer.json b/composer.json index bdedd225..4f6085ce 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ "funding": [ { "type": "github", - "url": "https://github.com/sponsors/cycle" + "url": "https://github.com/sponsors/cycle " } ], "require": { diff --git a/tests/ORM/Functional/Driver/Postgres/SerialColumnTest.php b/tests/ORM/Functional/Driver/Postgres/SerialColumnTest.php new file mode 100644 index 00000000..7afd3346 --- /dev/null +++ b/tests/ORM/Functional/Driver/Postgres/SerialColumnTest.php @@ -0,0 +1,73 @@ +getDatabase()->table('user')->getSchema(); + $schema->column('id')->type('uuid'); + $schema->column('balance')->type('serial')->nullable(false); + $schema->save(); + + $this->getDatabase()->table('user')->insertMultiple( + ['id'], + [ + [Uuid::uuid4()->toString()], + [Uuid::uuid4()->toString()], + [Uuid::uuid4()->toString()], + ] + ); + + $this->orm = $this->withSchema(new Schema([ + User::class => [ + SchemaInterface::ROLE => 'user', + SchemaInterface::MAPPER => Mapper::class, + SchemaInterface::DATABASE => 'default', + SchemaInterface::TABLE => 'user', + SchemaInterface::PRIMARY_KEY => 'id', + SchemaInterface::COLUMNS => ['id', 'balance'], + SchemaInterface::SCHEMA => [], + SchemaInterface::RELATIONS => [], + ], + ])); + } + + public function testPersist(): void + { + $this->logger->display(); + $u = new User(); + $u->id = Uuid::uuid4()->toString(); + + $this->save($u); + + $this->assertNotNull($u->balance); + + $this->orm->getHeap()->clean(); + + $s = (new Select($this->orm, User::class))->wherePK($u->id)->fetchOne(); + + $this->assertSame($u->balance, $s->balance); + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 5ccbab2b..ed6aaed0 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -25,7 +25,10 @@ user: 'root', password: 'root', ), - queryCache: true + queryCache: true, + options: [ + 'logQueryParameters' => true, + ], ), 'postgres' => new Config\PostgresDriverConfig( connection: new Config\Postgres\TcpConnectionConfig( @@ -37,6 +40,9 @@ ), schema: 'public', queryCache: true, + options: [ + 'logQueryParameters' => true, + ], ), 'sqlserver' => new Config\SQLServerDriverConfig( connection: new Config\SQLServer\TcpConnectionConfig( @@ -46,7 +52,10 @@ user: 'SA', password: 'SSpaSS__1' ), - queryCache: true + queryCache: true, + options: [ + 'logQueryParameters' => true, + ], ), ];