Skip to content

Commit 68ef774

Browse files
authored
Update tests according changes in db (#417)
1 parent 62f8370 commit 68ef774

File tree

1 file changed

+10
-77
lines changed

1 file changed

+10
-77
lines changed

tests/ColumnTest.php

Lines changed: 10 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use DateTimeImmutable;
88
use DateTimeZone;
99
use PHPUnit\Framework\Attributes\DataProviderExternal;
10+
use Yiisoft\Db\Connection\ConnectionInterface;
1011
use Yiisoft\Db\Constant\ColumnType;
1112
use Yiisoft\Db\Expression\ArrayExpression;
1213
use Yiisoft\Db\Expression\Expression;
@@ -19,7 +20,6 @@
1920
use Yiisoft\Db\Pgsql\Column\ColumnBuilder;
2021
use Yiisoft\Db\Pgsql\Column\IntegerColumn;
2122
use Yiisoft\Db\Pgsql\Column\StructuredColumn;
22-
use Yiisoft\Db\Pgsql\Connection;
2323
use Yiisoft\Db\Pgsql\Tests\Provider\ColumnProvider;
2424
use Yiisoft\Db\Pgsql\Tests\Support\TestTrait;
2525
use Yiisoft\Db\Query\Query;
@@ -30,6 +30,7 @@
3030
use Yiisoft\Db\Tests\Common\CommonColumnTest;
3131
use Yiisoft\Db\Tests\Support\Assert;
3232

33+
use function iterator_to_array;
3334
use function str_repeat;
3435
use function stream_get_contents;
3536

@@ -42,7 +43,7 @@ final class ColumnTest extends CommonColumnTest
4243

4344
protected const COLUMN_BUILDER = ColumnBuilder::class;
4445

45-
private function insertTypeValues(Connection $db): void
46+
protected function insertTypeValues(ConnectionInterface $db): void
4647
{
4748
$db->createCommand()->insert(
4849
'type',
@@ -69,7 +70,7 @@ private function insertTypeValues(Connection $db): void
6970
)->execute();
7071
}
7172

72-
private function assertTypecastedValues(array $result): void
73+
protected function assertTypecastedValues(array $result, bool $allTypecasted = false): void
7374
{
7475
$this->assertSame(1, $result['int_col']);
7576
$this->assertSame(str_repeat('x', 100), $result['char_col']);
@@ -90,44 +91,6 @@ private function assertTypecastedValues(array $result): void
9091
$this->assertSame([[[',', 'null', true, 'false', 'f']]], $result['jsonarray_col']);
9192
}
9293

93-
public function testQueryWithTypecasting(): void
94-
{
95-
$db = $this->getConnection(true);
96-
97-
$this->insertTypeValues($db);
98-
99-
$query = (new Query($db))->from('type')->withTypecasting();
100-
101-
$result = $query->one();
102-
103-
$this->assertTypecastedValues($result);
104-
105-
$result = $query->all();
106-
107-
$this->assertTypecastedValues($result[0]);
108-
109-
$db->close();
110-
}
111-
112-
public function testCommandWithPhpTypecasting(): void
113-
{
114-
$db = $this->getConnection(true);
115-
116-
$this->insertTypeValues($db);
117-
118-
$command = $db->createCommand('SELECT * FROM type')->withPhpTypecasting();
119-
120-
$result = $command->queryOne();
121-
122-
$this->assertTypecastedValues($result);
123-
124-
$result = $command->queryAll();
125-
126-
$this->assertTypecastedValues($result[0]);
127-
128-
$db->close();
129-
}
130-
13194
public function testSelectWithPhpTypecasting(): void
13295
{
13396
$db = $this->getConnection(true);
@@ -173,6 +136,12 @@ public function testSelectWithPhpTypecasting(): void
173136

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

139+
$result = $db->createCommand($sql)
140+
->withPhpTypecasting()
141+
->query();
142+
143+
$this->assertSame([$expected], iterator_to_array($result));
144+
176145
$result = $db->createCommand('SELECT 2.5')
177146
->withPhpTypecasting()
178147
->queryScalar();
@@ -188,27 +157,6 @@ public function testSelectWithPhpTypecasting(): void
188157
$db->close();
189158
}
190159

191-
public function testPhpTypeCast(): void
192-
{
193-
$db = $this->getConnection(true);
194-
$schema = $db->getSchema();
195-
$columns = $schema->getTableSchema('type')->getColumns();
196-
197-
$this->insertTypeValues($db);
198-
199-
$query = (new Query($db))->from('type')->one();
200-
201-
$result = [];
202-
203-
foreach ($columns as $columnName => $column) {
204-
$result[$columnName] = $column->phpTypecast($query[$columnName]);
205-
}
206-
207-
$this->assertTypecastedValues($result);
208-
209-
$db->close();
210-
}
211-
212160
public function testDbTypeCastJson(): void
213161
{
214162
$db = $this->getConnection(true);
@@ -271,21 +219,6 @@ public function testBoolDefault(): void
271219
$db->close();
272220
}
273221

274-
public function testNegativeDefaultValues()
275-
{
276-
$db = $this->getConnection(true);
277-
278-
$schema = $db->getSchema();
279-
$tableSchema = $schema->getTableSchema('negative_default_values');
280-
281-
$this->assertSame(-123, $tableSchema->getColumn('tinyint_col')->getDefaultValue());
282-
$this->assertSame(-123, $tableSchema->getColumn('smallint_col')->getDefaultValue());
283-
$this->assertSame(-123, $tableSchema->getColumn('int_col')->getDefaultValue());
284-
$this->assertSame(-123, $tableSchema->getColumn('bigint_col')->getDefaultValue());
285-
$this->assertSame(-12345.6789, $tableSchema->getColumn('float_col')->getDefaultValue());
286-
$this->assertSame(-33.22, $tableSchema->getColumn('numeric_col')->getDefaultValue());
287-
}
288-
289222
public function testPrimaryKeyOfView()
290223
{
291224
$db = $this->getConnection(true);

0 commit comments

Comments
 (0)