7
7
use DateTimeImmutable ;
8
8
use DateTimeZone ;
9
9
use PHPUnit \Framework \Attributes \DataProviderExternal ;
10
+ use Yiisoft \Db \Connection \ConnectionInterface ;
10
11
use Yiisoft \Db \Constant \ColumnType ;
11
12
use Yiisoft \Db \Expression \ArrayExpression ;
12
13
use Yiisoft \Db \Expression \Expression ;
19
20
use Yiisoft \Db \Pgsql \Column \ColumnBuilder ;
20
21
use Yiisoft \Db \Pgsql \Column \IntegerColumn ;
21
22
use Yiisoft \Db \Pgsql \Column \StructuredColumn ;
22
- use Yiisoft \Db \Pgsql \Connection ;
23
23
use Yiisoft \Db \Pgsql \Tests \Provider \ColumnProvider ;
24
24
use Yiisoft \Db \Pgsql \Tests \Support \TestTrait ;
25
25
use Yiisoft \Db \Query \Query ;
30
30
use Yiisoft \Db \Tests \Common \CommonColumnTest ;
31
31
use Yiisoft \Db \Tests \Support \Assert ;
32
32
33
+ use function iterator_to_array ;
33
34
use function str_repeat ;
34
35
use function stream_get_contents ;
35
36
@@ -42,7 +43,7 @@ final class ColumnTest extends CommonColumnTest
42
43
43
44
protected const COLUMN_BUILDER = ColumnBuilder::class;
44
45
45
- private function insertTypeValues (Connection $ db ): void
46
+ protected function insertTypeValues (ConnectionInterface $ db ): void
46
47
{
47
48
$ db ->createCommand ()->insert (
48
49
'type ' ,
@@ -69,7 +70,7 @@ private function insertTypeValues(Connection $db): void
69
70
)->execute ();
70
71
}
71
72
72
- private function assertTypecastedValues (array $ result ): void
73
+ protected function assertTypecastedValues (array $ result, bool $ allTypecasted = false ): void
73
74
{
74
75
$ this ->assertSame (1 , $ result ['int_col ' ]);
75
76
$ this ->assertSame (str_repeat ('x ' , 100 ), $ result ['char_col ' ]);
@@ -90,44 +91,6 @@ private function assertTypecastedValues(array $result): void
90
91
$ this ->assertSame ([[[', ' , 'null ' , true , 'false ' , 'f ' ]]], $ result ['jsonarray_col ' ]);
91
92
}
92
93
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
-
131
94
public function testSelectWithPhpTypecasting (): void
132
95
{
133
96
$ db = $ this ->getConnection (true );
@@ -173,6 +136,12 @@ public function testSelectWithPhpTypecasting(): void
173
136
174
137
$ this ->assertSame ([$ expected ], $ result );
175
138
139
+ $ result = $ db ->createCommand ($ sql )
140
+ ->withPhpTypecasting ()
141
+ ->query ();
142
+
143
+ $ this ->assertSame ([$ expected ], iterator_to_array ($ result ));
144
+
176
145
$ result = $ db ->createCommand ('SELECT 2.5 ' )
177
146
->withPhpTypecasting ()
178
147
->queryScalar ();
@@ -188,27 +157,6 @@ public function testSelectWithPhpTypecasting(): void
188
157
$ db ->close ();
189
158
}
190
159
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
-
212
160
public function testDbTypeCastJson (): void
213
161
{
214
162
$ db = $ this ->getConnection (true );
@@ -271,21 +219,6 @@ public function testBoolDefault(): void
271
219
$ db ->close ();
272
220
}
273
221
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
-
289
222
public function testPrimaryKeyOfView ()
290
223
{
291
224
$ db = $ this ->getConnection (true );
0 commit comments