Skip to content

Update tests according changes in db #333

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 3 commits into from
Jun 24, 2025
Merged
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
46 changes: 19 additions & 27 deletions tests/ColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
use PDO;
use PHPUnit\Framework\Attributes\DataProviderExternal;
use Yiisoft\Db\Command\Param;
use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Expression\Expression;
use Yiisoft\Db\Oracle\Column\BinaryColumn;
use Yiisoft\Db\Oracle\Column\ColumnBuilder;
use Yiisoft\Db\Oracle\Column\JsonColumn;
use Yiisoft\Db\Oracle\Connection;
use Yiisoft\Db\Oracle\Tests\Provider\ColumnProvider;
use Yiisoft\Db\Oracle\Tests\Support\TestTrait;
use Yiisoft\Db\Query\Query;
Expand All @@ -23,6 +23,7 @@
use Yiisoft\Db\Schema\Column\StringColumn;
use Yiisoft\Db\Tests\Common\CommonColumnTest;

use function iterator_to_array;
use function str_repeat;
use function stream_get_contents;
use function version_compare;
Expand All @@ -36,7 +37,7 @@ final class ColumnTest extends CommonColumnTest

protected const COLUMN_BUILDER = ColumnBuilder::class;

private function insertTypeValues(Connection $db): void
protected function insertTypeValues(ConnectionInterface $db): void
{
$db->createCommand()->insert(
'type',
Expand All @@ -56,7 +57,7 @@ private function insertTypeValues(Connection $db): void
)->execute();
}

private function assertTypecastedValues(array $result, bool $allTypecasted = false): void
protected function assertTypecastedValues(array $result, bool $allTypecasted = false): void
{
$utcTimezone = new DateTimeZone('UTC');

Expand All @@ -81,10 +82,10 @@ private function assertTypecastedValues(array $result, bool $allTypecasted = fal
public function testQueryWithTypecasting(): void
{
$db = $this->getConnection();
$varsion = $db->getServerInfo()->getVersion();
$version = $db->getServerInfo()->getVersion();
$db->close();

$isOldVersion = version_compare($varsion, '21', '<');
$isOldVersion = version_compare($version, '21', '<');

if (!$isOldVersion) {
$this->fixture = 'oci21.sql';
Expand All @@ -110,10 +111,10 @@ public function testQueryWithTypecasting(): void
public function testCommandWithPhpTypecasting(): void
{
$db = $this->getConnection();
$varsion = $db->getServerInfo()->getVersion();
$version = $db->getServerInfo()->getVersion();
$db->close();

$isOldVersion = version_compare($varsion, '21', '<');
$isOldVersion = version_compare($version, '21', '<');

if (!$isOldVersion) {
$this->fixture = 'oci21.sql';
Expand Down Expand Up @@ -161,6 +162,12 @@ public function testSelectWithPhpTypecasting(): void

$this->assertSame([$expected], $result);

$result = $db->createCommand($sql)
->withPhpTypecasting()
->query();

$this->assertSame([$expected], iterator_to_array($result));

$result = $db->createCommand('SELECT 2.5 FROM DUAL')
->withPhpTypecasting()
->queryScalar();
Expand All @@ -176,32 +183,17 @@ public function testSelectWithPhpTypecasting(): void
$db->close();
}

public function testPhpTypeCast(): void
public function testPhpTypecast(): void
{
$db = $this->getConnection();

if (version_compare($db->getServerInfo()->getVersion(), '21', '>=')) {
$this->fixture = 'oci21.sql';
}

$version = $db->getServerInfo()->getVersion();
$db->close();
$db = $this->getConnection(true);
$schema = $db->getSchema();
$columns = $schema->getTableSchema('type')->getColumns();

$this->insertTypeValues($db);

$query = (new Query($db))->from('type')->one();

$result = [];

foreach ($columns as $columnName => $column) {
$result[$columnName] = $column->phpTypecast($query[$columnName]);
if (version_compare($version, '21', '>=')) {
$this->fixture = 'oci21.sql';
}

$this->assertTypecastedValues($result, true);

$db->close();
parent::testPhpTypecast();
}

public function testColumnInstance(): void
Expand Down