Skip to content

Implement the ability for user-defined type casting #395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
}

if ($this->logger !== null) {
$command->setLogger($this->logger);

Check warning on line 34 in src/Connection.php

View workflow job for this annotation

GitHub Actions / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "MethodCallRemoval": @@ @@ $command->setSql($sql); } if ($this->logger !== null) { - $command->setLogger($this->logger); + } if ($this->profiler !== null) { $command->setProfiler($this->profiler);
}

if ($this->profiler !== null) {
Expand All @@ -48,7 +48,7 @@

public function getColumnFactory(): ColumnFactoryInterface
{
return new ColumnFactory();
return $this->columnFactory ??= new ColumnFactory();
}

public function getLastInsertID(?string $sequenceName = null): string
Expand Down
6 changes: 6 additions & 0 deletions tests/ColumnFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PHPUnit\Framework\Attributes\DataProviderExternal;
use Yiisoft\Db\Constant\ColumnType;
use Yiisoft\Db\Pgsql\Column\ArrayColumn;
use Yiisoft\Db\Pgsql\Column\ColumnFactory;
use Yiisoft\Db\Pgsql\Tests\Provider\ColumnFactoryProvider;
use Yiisoft\Db\Pgsql\Tests\Support\TestTrait;
use Yiisoft\Db\Schema\Column\ColumnInterface;
Expand All @@ -19,6 +20,11 @@ final class ColumnFactoryTest extends AbstractColumnFactoryTest
{
use TestTrait;

protected function getColumnFactoryClass(): string
{
return ColumnFactory::class;
}

#[DataProviderExternal(ColumnFactoryProvider::class, 'dbTypes')]
public function testFromDbType(string $dbType, string $expectedType, string $expectedInstanceOf): void
{
Expand Down
13 changes: 13 additions & 0 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Pgsql\Column\ColumnFactory;
use Yiisoft\Db\Pgsql\Connection;
use Yiisoft\Db\Pgsql\Tests\Support\TestTrait;
use Yiisoft\Db\Tests\Common\CommonConnectionTest;
use Yiisoft\Db\Tests\Support\DbHelper;
use Yiisoft\Db\Transaction\TransactionInterface;

/**
Expand Down Expand Up @@ -143,4 +145,15 @@ public function testGetColumnFactory(): void

$db->close();
}

public function testUserDefinedColumnFactory(): void
{
$columnFactory = new ColumnFactory();

$db = new Connection($this->getDriver(), DbHelper::getSchemaCache(), $columnFactory);

$this->assertSame($columnFactory, $db->getColumnFactory());

$db->close();
}
}
2 changes: 1 addition & 1 deletion tests/Support/TestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static function setUpBeforeClass(): void
$db->close();
}

private function getDriver(): PdoDriverInterface
protected function getDriver(): PdoDriverInterface
{
$driver = new Driver($this->getDsn(), self::getUsername(), self::getPassword());
$driver->charset('utf8');
Expand Down
Loading