Skip to content

Commit

Permalink
Add a test case
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Feb 5, 2024
1 parent c10b995 commit 1232aea
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 3 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/cycle"
"url": "https://github.com/sponsors/cycle "
}
],
"require": {
Expand Down
73 changes: 73 additions & 0 deletions tests/ORM/Functional/Driver/Postgres/SerialColumnTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

declare(strict_types=1);

namespace Cycle\ORM\Tests\Functional\Driver\Postgres;

use Cycle\ORM\Mapper\Mapper;
use Cycle\ORM\Schema;
use Cycle\ORM\SchemaInterface;
use Cycle\ORM\Select;
use Cycle\ORM\Tests\Fixtures\User;
use Cycle\ORM\Tests\Functional\Driver\Common\BaseTest;
use Cycle\ORM\Tests\Traits\TableTrait;
use Ramsey\Uuid\Uuid;

/**
* @group driver
* @group driver-postgres
*/
final class SerialColumnTest extends BaseTest
{
public const DRIVER = 'postgres';
use TableTrait;

public function setUp(): void
{
parent::setUp();

$schema = $this->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);
}
}
13 changes: 11 additions & 2 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
user: 'root',
password: 'root',
),
queryCache: true
queryCache: true,
options: [
'logQueryParameters' => true,
],
),
'postgres' => new Config\PostgresDriverConfig(
connection: new Config\Postgres\TcpConnectionConfig(
Expand All @@ -37,6 +40,9 @@
),
schema: 'public',
queryCache: true,
options: [
'logQueryParameters' => true,
],
),
'sqlserver' => new Config\SQLServerDriverConfig(
connection: new Config\SQLServer\TcpConnectionConfig(
Expand All @@ -46,7 +52,10 @@
user: 'SA',
password: 'SSpaSS__1'
),
queryCache: true
queryCache: true,
options: [
'logQueryParameters' => true,
],
),
];

Expand Down

0 comments on commit 1232aea

Please sign in to comment.