Skip to content

Commit e1ae712

Browse files
Remove src\TestSupport from yiisoft\db. (#188)
* Remove src\TestSupport from yiisoft\db.
1 parent d5a9848 commit e1ae712

14 files changed

Lines changed: 317 additions & 329 deletions

src/ConnectionPDO.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function createTransaction(): TransactionInterface
4949
public function getLastInsertID(string $sequenceName = null): string
5050
{
5151
if ($sequenceName === null) {
52-
throw new InvalidArgumentException('PgSQL not support lastInsertId without sequence name');
52+
throw new InvalidArgumentException('PostgreSQL not support lastInsertId without sequence name.');
5353
}
5454

5555
return parent::getLastInsertID($sequenceName);

tests/ArrayParserTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44

55
namespace Yiisoft\Db\Pgsql\Tests;
66

7+
use PHPUnit\Framework\TestCase;
78
use Yiisoft\Db\Pgsql\ArrayParser;
89

910
/**
1011
* @group pgsql
12+
*
13+
* @psalm-suppress PropertyNotSetInConstructor
1114
*/
1215
final class ArrayParserTest extends TestCase
1316
{

tests/BatchQueryResultTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
/**
1111
* @group pgsql
12+
*
13+
* @psalm-suppress PropertyNotSetInConstructor
1214
*/
1315
final class BatchQueryResultTest extends CommonBatchQueryResultTest
1416
{

tests/ColumnSchemaTest.php

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,38 @@
44

55
namespace Yiisoft\Db\Pgsql\Tests;
66

7+
use JsonException;
8+
use PHPUnit\Framework\TestCase;
9+
use Throwable;
10+
use Yiisoft\Db\Exception\Exception;
11+
use Yiisoft\Db\Exception\InvalidConfigException;
712
use Yiisoft\Db\Expression\ArrayExpression;
813
use Yiisoft\Db\Expression\JsonExpression;
9-
use Yiisoft\Db\Query\Query;
1014
use Yiisoft\Db\Pgsql\ColumnSchema;
15+
use Yiisoft\Db\Pgsql\Tests\Support\TestTrait;
16+
use Yiisoft\Db\Query\Query;
1117

1218
/**
1319
* @group pgsql
20+
*
21+
* @psalm-suppress PropertyNotSetInConstructor
1422
*/
1523
final class ColumnSchemaTest extends TestCase
1624
{
25+
use TestTrait;
26+
27+
/**
28+
* @throws Exception
29+
* @throws InvalidConfigException
30+
* @throws Throwable
31+
*/
1732
public function testPhpTypeCast(): void
1833
{
1934
$db = $this->getConnection(true);
35+
2036
$command = $db->createCommand();
2137
$schema = $db->getSchema();
2238
$tableSchema = $schema->getTableSchema('type');
23-
2439
$command->insert(
2540
'type',
2641
[
@@ -38,9 +53,7 @@ public function testPhpTypeCast(): void
3853
'jsonarray_col' => [new ArrayExpression([[',', 'null', true, 'false', 'f']], 'json')],
3954
]
4055
);
41-
4256
$command->execute();
43-
4457
$query = (new Query($db))->from('type')->one();
4558

4659
$this->assertNotNull($tableSchema);
@@ -59,18 +72,24 @@ public function testPhpTypeCast(): void
5972
$this->assertSame(1, $intColPhpTypeCast);
6073
$this->assertSame(str_repeat('x', 100), $charColPhpTypeCast);
6174
$this->assertSame(1.234, $floatColPhpTypeCast);
62-
$this->assertSame(false, $boolColPhpTypeCast);
75+
$this->assertFalse($boolColPhpTypeCast);
6376
$this->assertSame('33.22', $numericColPhpTypeCast);
6477
$this->assertSame([1, -2, null, 42], $intArrayColPhpType);
65-
$this->assertSame(null, $textArray2ColPhpType);
78+
$this->assertNull($textArray2ColPhpType);
6679
$this->assertSame([['a' => 1, 'b' => null, 'c' => [1, 3, 5]]], $jsonColPhpType);
6780
$this->assertSame(['1', '2', '3'], $jsonBColPhpType);
6881
$this->assertSame([[[',', 'null', true, 'false', 'f']]], $jsonArrayColPhpType);
82+
83+
$db->close();
6984
}
7085

86+
/**
87+
* @throws JsonException
88+
*/
7189
public function testPhpTypeCastBool(): void
7290
{
7391
$columnSchema = new ColumnSchema();
92+
7493
$columnSchema->type('boolean');
7594

7695
$this->assertFalse($columnSchema->phpTypeCast('false'));

tests/CommandTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public function testAddDefaultValue(): void
4141
);
4242

4343
$command->addDefaultValue('{{name}}', '{{table}}', 'column', 'value');
44+
45+
$db->close();
4446
}
4547

4648
/**
@@ -93,6 +95,8 @@ public function testBooleanValuesInsert(): void
9395
);
9496

9597
$this->assertSame(1, $command->queryScalar());
98+
99+
$db->close();
96100
}
97101

98102
/**
@@ -124,6 +128,8 @@ public function testBooleanValuesBatchInsert(): void
124128
);
125129

126130
$this->assertSame(1, $command->queryScalar());
131+
132+
$db->close();
127133
}
128134

129135
/**
@@ -148,6 +154,8 @@ public function testDelete(): void
148154
$command->setSql($chekSql);
149155

150156
$this->assertSame(1, $command->queryScalar());
157+
158+
$db->close();
151159
}
152160

153161
/**
@@ -166,6 +174,8 @@ public function testDropDefaultValue(): void
166174
);
167175

168176
$command->dropDefaultValue('{{name}}', '{{table}}');
177+
178+
$db->close();
169179
}
170180

171181
/**
@@ -209,6 +219,8 @@ public function testIssue15827(): void
209219

210220
$this->assertSame(1, $found);
211221
$this->assertSame(1, $command->delete('{{array_and_json_types}}')->execute());
222+
223+
$db->close();
212224
}
213225

214226
/**
@@ -251,10 +263,15 @@ public function testSaveSerializedObject(): void
251263
$command->update('{{type}}', ['blob_col' => serialize($db)], ['char_col' => 'serialize']);
252264

253265
$this->assertSame(1, $command->execute());
266+
267+
$db->close();
254268
}
255269

256270
/**
257271
* @dataProvider \Yiisoft\Db\Pgsql\Tests\Provider\CommandProvider::update()
272+
*
273+
* @throws Exception
274+
* @throws Throwable
258275
*/
259276
public function testUpdate(
260277
string $table,
@@ -268,6 +285,9 @@ public function testUpdate(
268285

269286
/**
270287
* @dataProvider \Yiisoft\Db\Pgsql\Tests\Provider\CommandProvider::upsert()
288+
*
289+
* @throws Exception
290+
* @throws Throwable
271291
*/
272292
public function testUpsert(array $firstData, array $secondData): void
273293
{

tests/ConnectionPDOTest.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Yiisoft\Db\Pgsql\Tests;
6+
7+
use Throwable;
8+
use Yiisoft\Db\Exception\Exception;
9+
use Yiisoft\Db\Exception\InvalidArgumentException;
10+
use Yiisoft\Db\Exception\InvalidCallException;
11+
use Yiisoft\Db\Exception\InvalidConfigException;
12+
use Yiisoft\Db\Pgsql\Tests\Support\TestTrait;
13+
use Yiisoft\Db\Tests\Common\CommonConnectionPDOTest;
14+
15+
/**
16+
* @group pgsql
17+
*
18+
* @psalm-suppress PropertyNotSetInConstructor
19+
*/
20+
final class ConnectionPDOTest extends CommonConnectionPDOTest
21+
{
22+
use TestTrait;
23+
24+
/**
25+
* @throws Exception
26+
* @throws InvalidConfigException
27+
* @throws InvalidCallException
28+
* @throws Throwable
29+
*/
30+
public function testGetLastInsertID(): void
31+
{
32+
$db = $this->getConnection(true);
33+
34+
$command = $db->createCommand();
35+
$command->insert(
36+
'customer',
37+
[
38+
'name' => 'Some {{weird}} name',
39+
'email' => 'test@example.com',
40+
'address' => 'Some {{%weird}} address',
41+
]
42+
)->execute();
43+
44+
$this->assertSame('4', $db->getLastInsertID('public.customer_id_seq'));
45+
46+
$db->close();
47+
}
48+
49+
/**
50+
* @throws Exception
51+
* @throws InvalidConfigException
52+
* @throws InvalidCallException
53+
* @throws Throwable
54+
*/
55+
public function testGetLastInsertIDWithException(): void
56+
{
57+
$db = $this->getConnection(true);
58+
59+
$command = $db->createCommand();
60+
$command->insert('item', ['name' => 'Yii2 starter', 'category_id' => 1])->execute();
61+
$command->insert('item', ['name' => 'Yii3 starter', 'category_id' => 1])->execute();
62+
63+
$this->expectException(InvalidArgumentException::class);
64+
$this->expectExceptionMessage('PostgreSQL not support lastInsertId without sequence name.');
65+
66+
$db->getLastInsertID();
67+
}
68+
}

0 commit comments

Comments
 (0)