Skip to content

Commit a19a6e2

Browse files
authored
Update tests according changes in db (#369)
1 parent b925477 commit a19a6e2

File tree

1 file changed

+10
-63
lines changed

1 file changed

+10
-63
lines changed

tests/ColumnTest.php

Lines changed: 10 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@
99
use PDO;
1010
use PHPUnit\Framework\Attributes\DataProviderExternal;
1111
use Yiisoft\Db\Command\Param;
12+
use Yiisoft\Db\Connection\ConnectionInterface;
1213
use Yiisoft\Db\Expression\Expression;
1314
use Yiisoft\Db\Mssql\Column\BinaryColumn;
1415
use Yiisoft\Db\Mssql\Column\ColumnBuilder;
15-
use Yiisoft\Db\Mssql\Connection;
1616
use Yiisoft\Db\Mssql\Tests\Provider\ColumnProvider;
1717
use Yiisoft\Db\Mssql\Tests\Support\TestTrait;
18-
use Yiisoft\Db\Query\Query;
1918
use Yiisoft\Db\Schema\Column\BooleanColumn;
2019
use Yiisoft\Db\Schema\Column\ColumnInterface;
2120
use Yiisoft\Db\Schema\Column\DoubleColumn;
2221
use Yiisoft\Db\Schema\Column\IntegerColumn;
2322
use Yiisoft\Db\Schema\Column\StringColumn;
2423
use Yiisoft\Db\Tests\Common\CommonColumnTest;
2524

25+
use function iterator_to_array;
2626
use function str_repeat;
2727

2828
/**
@@ -34,7 +34,7 @@ final class ColumnTest extends CommonColumnTest
3434

3535
protected const COLUMN_BUILDER = ColumnBuilder::class;
3636

37-
private function insertTypeValues(Connection $db): void
37+
protected function insertTypeValues(ConnectionInterface $db): void
3838
{
3939
$db->createCommand()->insert(
4040
'type',
@@ -51,7 +51,7 @@ private function insertTypeValues(Connection $db): void
5151
)->execute();
5252
}
5353

54-
private function assertTypecastedValues(array $result, bool $allTypecasted = false): void
54+
protected function assertTypecastedValues(array $result, bool $allTypecasted = false): void
5555
{
5656
$this->assertSame(1, $result['int_col']);
5757
$this->assertSame(str_repeat('x', 100), $result['char_col']);
@@ -68,44 +68,6 @@ private function assertTypecastedValues(array $result, bool $allTypecasted = fal
6868
}
6969
}
7070

71-
public function testQueryWithTypecasting(): void
72-
{
73-
$db = $this->getConnection(true);
74-
75-
$this->insertTypeValues($db);
76-
77-
$query = (new Query($db))->from('type')->withTypecasting();
78-
79-
$result = $query->one();
80-
81-
$this->assertTypecastedValues($result);
82-
83-
$result = $query->all();
84-
85-
$this->assertTypecastedValues($result[0]);
86-
87-
$db->close();
88-
}
89-
90-
public function testCommandWithPhpTypecasting(): void
91-
{
92-
$db = $this->getConnection(true);
93-
94-
$this->insertTypeValues($db);
95-
96-
$command = $db->createCommand('SELECT * FROM type')->withPhpTypecasting();
97-
98-
$result = $command->queryOne();
99-
100-
$this->assertTypecastedValues($result);
101-
102-
$result = $command->queryAll();
103-
104-
$this->assertTypecastedValues($result[0]);
105-
106-
$db->close();
107-
}
108-
10971
public function testSelectWithPhpTypecasting(): void
11072
{
11173
$db = $this->getConnection();
@@ -131,6 +93,12 @@ public function testSelectWithPhpTypecasting(): void
13193

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

96+
$result = $db->createCommand($sql)
97+
->withPhpTypecasting()
98+
->query();
99+
100+
$this->assertSame([$expected], iterator_to_array($result));
101+
134102
$result = $db->createCommand('SELECT 2.5')
135103
->withPhpTypecasting()
136104
->queryScalar();
@@ -146,27 +114,6 @@ public function testSelectWithPhpTypecasting(): void
146114
$db->close();
147115
}
148116

149-
public function testPhpTypeCast(): void
150-
{
151-
$db = $this->getConnection(true);
152-
$schema = $db->getSchema();
153-
$columns = $schema->getTableSchema('type')->getColumns();
154-
155-
$this->insertTypeValues($db);
156-
157-
$query = (new Query($db))->from('type')->one();
158-
159-
$result = [];
160-
161-
foreach ($columns as $columnName => $column) {
162-
$result[$columnName] = $column->phpTypecast($query[$columnName]);
163-
}
164-
165-
$this->assertTypecastedValues($result, true);
166-
167-
$db->close();
168-
}
169-
170117
public function testColumnInstance()
171118
{
172119
$db = $this->getConnection(true);

0 commit comments

Comments
 (0)