9
9
use PDO ;
10
10
use PHPUnit \Framework \Attributes \DataProviderExternal ;
11
11
use Yiisoft \Db \Command \Param ;
12
+ use Yiisoft \Db \Connection \ConnectionInterface ;
12
13
use Yiisoft \Db \Expression \Expression ;
13
14
use Yiisoft \Db \Mssql \Column \BinaryColumn ;
14
15
use Yiisoft \Db \Mssql \Column \ColumnBuilder ;
15
- use Yiisoft \Db \Mssql \Connection ;
16
16
use Yiisoft \Db \Mssql \Tests \Provider \ColumnProvider ;
17
17
use Yiisoft \Db \Mssql \Tests \Support \TestTrait ;
18
- use Yiisoft \Db \Query \Query ;
19
18
use Yiisoft \Db \Schema \Column \BooleanColumn ;
20
19
use Yiisoft \Db \Schema \Column \ColumnInterface ;
21
20
use Yiisoft \Db \Schema \Column \DoubleColumn ;
22
21
use Yiisoft \Db \Schema \Column \IntegerColumn ;
23
22
use Yiisoft \Db \Schema \Column \StringColumn ;
24
23
use Yiisoft \Db \Tests \Common \CommonColumnTest ;
25
24
25
+ use function iterator_to_array ;
26
26
use function str_repeat ;
27
27
28
28
/**
@@ -34,7 +34,7 @@ final class ColumnTest extends CommonColumnTest
34
34
35
35
protected const COLUMN_BUILDER = ColumnBuilder::class;
36
36
37
- private function insertTypeValues (Connection $ db ): void
37
+ protected function insertTypeValues (ConnectionInterface $ db ): void
38
38
{
39
39
$ db ->createCommand ()->insert (
40
40
'type ' ,
@@ -51,7 +51,7 @@ private function insertTypeValues(Connection $db): void
51
51
)->execute ();
52
52
}
53
53
54
- private function assertTypecastedValues (array $ result , bool $ allTypecasted = false ): void
54
+ protected function assertTypecastedValues (array $ result , bool $ allTypecasted = false ): void
55
55
{
56
56
$ this ->assertSame (1 , $ result ['int_col ' ]);
57
57
$ this ->assertSame (str_repeat ('x ' , 100 ), $ result ['char_col ' ]);
@@ -68,44 +68,6 @@ private function assertTypecastedValues(array $result, bool $allTypecasted = fal
68
68
}
69
69
}
70
70
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
-
109
71
public function testSelectWithPhpTypecasting (): void
110
72
{
111
73
$ db = $ this ->getConnection ();
@@ -131,6 +93,12 @@ public function testSelectWithPhpTypecasting(): void
131
93
132
94
$ this ->assertSame ([$ expected ], $ result );
133
95
96
+ $ result = $ db ->createCommand ($ sql )
97
+ ->withPhpTypecasting ()
98
+ ->query ();
99
+
100
+ $ this ->assertSame ([$ expected ], iterator_to_array ($ result ));
101
+
134
102
$ result = $ db ->createCommand ('SELECT 2.5 ' )
135
103
->withPhpTypecasting ()
136
104
->queryScalar ();
@@ -146,27 +114,6 @@ public function testSelectWithPhpTypecasting(): void
146
114
$ db ->close ();
147
115
}
148
116
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
-
170
117
public function testColumnInstance ()
171
118
{
172
119
$ db = $ this ->getConnection (true );
0 commit comments