33
44namespace tests \orm ;
55
6- use PHPUnit \Framework \TestCase ;
76use tests \stubs \FieldTypeModel ;
87use tests \stubs \TestFieldJsonDTO ;
98use tests \stubs \TestFieldPhpDTO ;
10- use think \ facade \ Db ;
9+ use tests \ TestCaseBase ;
1110
12- class ModelFieldTypeTest extends TestCase
11+ class ModelFieldTypeBase extends TestCaseBase
1312{
14- public static function setUpBeforeClass (): void
13+ protected function provideTestData (): array
1514 {
16- Db::execute ('DROP TABLE IF EXISTS `test_field_type`; ' );
17- Db::execute (
18- <<<SQL
19- CREATE TABLE `test_field_type` (
20- `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
21- `t_json` json DEFAULT NULL,
22- `t_php` varchar(512) DEFAULT NULL,
23- `bigint` bigint UNSIGNED DEFAULT NULL
24- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
25- SQL
26- );
27- }
28-
29- public function testFieldTypeSelect ()
30- {
31- $ data = [
15+ return [
3216 ['id ' => 1 , 't_json ' => '{"num1": 1, "str1": "a"} ' , 't_php ' => (string ) (new TestFieldPhpDTO (1 , 'a ' )), 'bigint ' => '0 ' ],
3317 ['id ' => 2 , 't_json ' => '{"num1": 2, "str1": "b"} ' , 't_php ' => (string ) (new TestFieldPhpDTO (2 , 'b ' )), 'bigint ' => '244791959321042944 ' ],
3418 ['id ' => 3 , 't_json ' => '{"num1": 3, "str1": "c"} ' , 't_php ' => (string ) (new TestFieldPhpDTO (3 , 'c ' )), 'bigint ' => '18374686479671623679 ' ],
3519 ];
20+ }
21+
22+ public static function setUpBeforeClass (): void
23+ {
24+ parent ::setUpBeforeClass ();
25+
26+ self ::initModelSupport ();
27+ }
3628
37- (new FieldTypeModel ())->insertAll ($ data );
29+ public function testInitData (): array
30+ {
31+ $ this ->db ->execute ('TRUNCATE TABLE test_field_type; ' );
32+
33+ $ data = $ this ->provideTestData ();
34+ self ::compatibleModelInsertAll (new FieldTypeModel (), $ data );
35+
36+ return $ data ;
37+ }
38+
39+ /**
40+ * @depends testInitData
41+ */
42+ public function testFieldTypeSelect (array $ data )
43+ {
44+ var_dump ($ this ->db ->getTableFieldsInfo ('test_field_type ' ));
45+ var_dump ($ this ->db ->getSchemaInfo ('test_field_type ' ));
46+ var_dump ($ this ->db ->getFieldBindType ('bigint ' ));
3847
39- $ result = Db:: table ('test_field_type ' )->select ();
48+ $ result = $ this -> db -> table ('test_field_type ' )-> setFieldType ([ ' bigint ' => ' string ' ] )->select ();
4049 $ this ->assertNotEmpty ($ result ->count ());
4150 foreach ($ data as $ index => $ item ) {
4251 $ this ->assertEquals ($ item , $ result [$ index ]);
@@ -52,7 +61,7 @@ public function testFieldTypeSelect()
5261 }
5362
5463 /**
55- * @depends testFieldTypeSelect
64+ * @depends testInitData
5665 */
5766 public function testFieldReadAndWrite ()
5867 {
@@ -69,9 +78,6 @@ public function testFieldReadAndWrite()
6978 $ this ->assertEquals ($ result ->id , $ result ->t_php ->getId ());
7079 }
7180
72- /**
73- * @depends testFieldTypeSelect
74- */
7581 public function testFieldReadInvalid ()
7682 {
7783
0 commit comments