Skip to content

Commit 873645b

Browse files
authored
Implement the ability for user-defined type casting (#314)
1 parent 1af51f9 commit 873645b

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

Diff for: src/Connection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function createTransaction(): TransactionInterface
5151

5252
public function getColumnFactory(): ColumnFactoryInterface
5353
{
54-
return new ColumnFactory();
54+
return $this->columnFactory ??= new ColumnFactory();
5555
}
5656

5757
/**

Diff for: tests/ColumnFactoryTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Yiisoft\Db\Oracle\Tests;
66

77
use PHPUnit\Framework\Attributes\DataProviderExternal;
8+
use Yiisoft\Db\Oracle\Column\ColumnFactory;
89
use Yiisoft\Db\Oracle\Tests\Provider\ColumnFactoryProvider;
910
use Yiisoft\Db\Oracle\Tests\Support\TestTrait;
1011
use Yiisoft\Db\Schema\Column\ColumnInterface;
@@ -17,6 +18,11 @@ final class ColumnFactoryTest extends AbstractColumnFactoryTest
1718
{
1819
use TestTrait;
1920

21+
protected function getColumnFactoryClass(): string
22+
{
23+
return ColumnFactory::class;
24+
}
25+
2026
#[DataProviderExternal(ColumnFactoryProvider::class, 'dbTypes')]
2127
public function testFromDbType(string $dbType, string $expectedType, string $expectedInstanceOf): void
2228
{

Diff for: tests/ConnectionTest.php

+15
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
use Yiisoft\Db\Exception\InvalidConfigException;
1313
use Yiisoft\Db\Exception\NotSupportedException;
1414
use Yiisoft\Db\Oracle\Column\ColumnFactory;
15+
use Yiisoft\Db\Oracle\Connection;
1516
use Yiisoft\Db\Oracle\Tests\Support\TestTrait;
1617
use Yiisoft\Db\Tests\Common\CommonConnectionTest;
18+
use Yiisoft\Db\Tests\Support\DbHelper;
1719
use Yiisoft\Db\Transaction\TransactionInterface;
1820

1921
/**
@@ -137,5 +139,18 @@ public function testGetColumnFactory(): void
137139
$db = $this->getConnection();
138140

139141
$this->assertInstanceOf(ColumnFactory::class, $db->getColumnFactory());
142+
143+
$db->close();
144+
}
145+
146+
public function testUserDefinedColumnFactory(): void
147+
{
148+
$columnFactory = new ColumnFactory();
149+
150+
$db = new Connection($this->getDriver(), DbHelper::getSchemaCache(), $columnFactory);
151+
152+
$this->assertSame($columnFactory, $db->getColumnFactory());
153+
154+
$db->close();
140155
}
141156
}

Diff for: tests/Support/TestTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ protected function setDsn(string $dsn): void
7070
$this->dsn = $dsn;
7171
}
7272

73-
private function getDriver(): PdoDriverInterface
73+
protected function getDriver(): PdoDriverInterface
7474
{
7575
return new Driver($this->getDsn(), self::getUsername(), self::getPassword());
7676
}

0 commit comments

Comments
 (0)