44
55namespace 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 ;
712use Yiisoft \Db \Expression \ArrayExpression ;
813use Yiisoft \Db \Expression \JsonExpression ;
9- use Yiisoft \Db \Query \Query ;
1014use 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 */
1523final 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 ' ));
0 commit comments