From 55a2932171631e9eb37128843b49a8326bf3955a Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 30 Jan 2024 10:03:05 +0900 Subject: [PATCH 1/5] test: rename test method name --- tests/system/Database/Live/AbstractGetFieldDataTest.php | 2 +- tests/system/Database/Live/MySQLi/GetFieldDataTest.php | 2 +- tests/system/Database/Live/OCI8/GetFieldDataTest.php | 2 +- tests/system/Database/Live/Postgre/GetFieldDataTest.php | 2 +- tests/system/Database/Live/SQLSRV/GetFieldDataTest.php | 2 +- tests/system/Database/Live/SQLite3/GetFieldDataTest.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/system/Database/Live/AbstractGetFieldDataTest.php b/tests/system/Database/Live/AbstractGetFieldDataTest.php index 570061cac3e3..d7484607c928 100644 --- a/tests/system/Database/Live/AbstractGetFieldDataTest.php +++ b/tests/system/Database/Live/AbstractGetFieldDataTest.php @@ -91,5 +91,5 @@ protected function createTable() $this->forge->createTable('test1'); } - abstract public function testGetFieldData(): void; + abstract public function testGetFieldDataDefault(): void; } diff --git a/tests/system/Database/Live/MySQLi/GetFieldDataTest.php b/tests/system/Database/Live/MySQLi/GetFieldDataTest.php index aacc7fa84b99..7d7e4012fa38 100644 --- a/tests/system/Database/Live/MySQLi/GetFieldDataTest.php +++ b/tests/system/Database/Live/MySQLi/GetFieldDataTest.php @@ -46,7 +46,7 @@ private function isOldMySQL(): bool ); } - public function testGetFieldData(): void + public function testGetFieldDataDefault(): void { $fields = $this->db->getFieldData('test1'); diff --git a/tests/system/Database/Live/OCI8/GetFieldDataTest.php b/tests/system/Database/Live/OCI8/GetFieldDataTest.php index 28763a11f3ee..0fd789c6d387 100644 --- a/tests/system/Database/Live/OCI8/GetFieldDataTest.php +++ b/tests/system/Database/Live/OCI8/GetFieldDataTest.php @@ -32,7 +32,7 @@ protected function createForge(): void $this->forge = Database::forge($this->db); } - public function testGetFieldData(): void + public function testGetFieldDataDefault(): void { $fields = $this->db->getFieldData('test1'); diff --git a/tests/system/Database/Live/Postgre/GetFieldDataTest.php b/tests/system/Database/Live/Postgre/GetFieldDataTest.php index 64caac6126b3..ad62a7a38cb5 100644 --- a/tests/system/Database/Live/Postgre/GetFieldDataTest.php +++ b/tests/system/Database/Live/Postgre/GetFieldDataTest.php @@ -32,7 +32,7 @@ protected function createForge(): void $this->forge = Database::forge($this->db); } - public function testGetFieldData(): void + public function testGetFieldDataDefault(): void { $fields = $this->db->getFieldData('test1'); diff --git a/tests/system/Database/Live/SQLSRV/GetFieldDataTest.php b/tests/system/Database/Live/SQLSRV/GetFieldDataTest.php index 07a41cd1467e..80af8543fffe 100644 --- a/tests/system/Database/Live/SQLSRV/GetFieldDataTest.php +++ b/tests/system/Database/Live/SQLSRV/GetFieldDataTest.php @@ -32,7 +32,7 @@ protected function createForge(): void $this->forge = Database::forge($this->db); } - public function testGetFieldData(): void + public function testGetFieldDataDefault(): void { $fields = $this->db->getFieldData('test1'); diff --git a/tests/system/Database/Live/SQLite3/GetFieldDataTest.php b/tests/system/Database/Live/SQLite3/GetFieldDataTest.php index 4b8b9bcd6432..9febf7bba45d 100644 --- a/tests/system/Database/Live/SQLite3/GetFieldDataTest.php +++ b/tests/system/Database/Live/SQLite3/GetFieldDataTest.php @@ -36,7 +36,7 @@ protected function createForge(): void $this->forge = Database::forge($config); } - public function testGetFieldData(): void + public function testGetFieldDataDefault(): void { $fields = $this->db->getFieldData('test1'); From 53d592ad0e1c6db996f9adf5da47b35db75431d0 Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 30 Jan 2024 10:07:51 +0900 Subject: [PATCH 2/5] test: add property $table --- tests/system/Database/Live/AbstractGetFieldDataTest.php | 7 ++++--- tests/system/Database/Live/MySQLi/GetFieldDataTest.php | 2 +- tests/system/Database/Live/OCI8/GetFieldDataTest.php | 2 +- tests/system/Database/Live/SQLSRV/GetFieldDataTest.php | 2 +- tests/system/Database/Live/SQLite3/GetFieldDataTest.php | 8 ++++---- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/tests/system/Database/Live/AbstractGetFieldDataTest.php b/tests/system/Database/Live/AbstractGetFieldDataTest.php index d7484607c928..ebea3cbcd47d 100644 --- a/tests/system/Database/Live/AbstractGetFieldDataTest.php +++ b/tests/system/Database/Live/AbstractGetFieldDataTest.php @@ -26,6 +26,7 @@ abstract class AbstractGetFieldDataTest extends CIUnitTestCase protected $db; protected Forge $forge; + protected string $table = 'test1'; protected function setUp(): void { @@ -46,12 +47,12 @@ protected function tearDown(): void { parent::tearDown(); - $this->forge->dropTable('test1', true); + $this->forge->dropTable($this->table, true); } protected function createTable() { - $this->forge->dropTable('test1', true); + $this->forge->dropTable($this->table, true); $this->forge->addField([ 'id' => [ @@ -88,7 +89,7 @@ protected function createTable() ], ]); $this->forge->addKey('id', true); - $this->forge->createTable('test1'); + $this->forge->createTable($this->table); } abstract public function testGetFieldDataDefault(): void; diff --git a/tests/system/Database/Live/MySQLi/GetFieldDataTest.php b/tests/system/Database/Live/MySQLi/GetFieldDataTest.php index 7d7e4012fa38..547d45eace91 100644 --- a/tests/system/Database/Live/MySQLi/GetFieldDataTest.php +++ b/tests/system/Database/Live/MySQLi/GetFieldDataTest.php @@ -48,7 +48,7 @@ private function isOldMySQL(): bool public function testGetFieldDataDefault(): void { - $fields = $this->db->getFieldData('test1'); + $fields = $this->db->getFieldData($this->table); $this->assertJsonStringEqualsJsonString( json_encode([ diff --git a/tests/system/Database/Live/OCI8/GetFieldDataTest.php b/tests/system/Database/Live/OCI8/GetFieldDataTest.php index 0fd789c6d387..a6dc3156b248 100644 --- a/tests/system/Database/Live/OCI8/GetFieldDataTest.php +++ b/tests/system/Database/Live/OCI8/GetFieldDataTest.php @@ -34,7 +34,7 @@ protected function createForge(): void public function testGetFieldDataDefault(): void { - $fields = $this->db->getFieldData('test1'); + $fields = $this->db->getFieldData($this->table); $data = []; diff --git a/tests/system/Database/Live/SQLSRV/GetFieldDataTest.php b/tests/system/Database/Live/SQLSRV/GetFieldDataTest.php index 80af8543fffe..60d60577130c 100644 --- a/tests/system/Database/Live/SQLSRV/GetFieldDataTest.php +++ b/tests/system/Database/Live/SQLSRV/GetFieldDataTest.php @@ -34,7 +34,7 @@ protected function createForge(): void public function testGetFieldDataDefault(): void { - $fields = $this->db->getFieldData('test1'); + $fields = $this->db->getFieldData($this->table); $this->assertJsonStringEqualsJsonString( json_encode([ diff --git a/tests/system/Database/Live/SQLite3/GetFieldDataTest.php b/tests/system/Database/Live/SQLite3/GetFieldDataTest.php index 9febf7bba45d..69cc9e01b7b2 100644 --- a/tests/system/Database/Live/SQLite3/GetFieldDataTest.php +++ b/tests/system/Database/Live/SQLite3/GetFieldDataTest.php @@ -38,7 +38,7 @@ protected function createForge(): void public function testGetFieldDataDefault(): void { - $fields = $this->db->getFieldData('test1'); + $fields = $this->db->getFieldData($this->table); $this->assertJsonStringEqualsJsonString( json_encode([ @@ -105,7 +105,7 @@ public function testGetFieldDataDefault(): void protected function createTableCompositePrimaryKey() { - $this->forge->dropTable('test1', true); + $this->forge->dropTable($this->table, true); $this->forge->addField([ 'pk1' => [ @@ -122,14 +122,14 @@ protected function createTableCompositePrimaryKey() ], ]); $this->forge->addPrimaryKey(['pk1', 'pk2']); - $this->forge->createTable('test1'); + $this->forge->createTable($this->table); } public function testGetFieldDataCompositePrimaryKey(): void { $this->createTableCompositePrimaryKey(); - $fields = $this->db->getFieldData('test1'); + $fields = $this->db->getFieldData($this->table); $this->assertJsonStringEqualsJsonString( json_encode([ From 956e815858835e2d573a444a15c3293e13cab62b Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 30 Jan 2024 10:10:19 +0900 Subject: [PATCH 3/5] test: rename method name --- tests/system/Database/Live/AbstractGetFieldDataTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/system/Database/Live/AbstractGetFieldDataTest.php b/tests/system/Database/Live/AbstractGetFieldDataTest.php index ebea3cbcd47d..9d9eb89474e6 100644 --- a/tests/system/Database/Live/AbstractGetFieldDataTest.php +++ b/tests/system/Database/Live/AbstractGetFieldDataTest.php @@ -35,7 +35,7 @@ protected function setUp(): void $this->db = Database::connect($this->DBGroup); $this->createForge(); - $this->createTable(); + $this->createTableForDefault(); } /** @@ -50,7 +50,7 @@ protected function tearDown(): void $this->forge->dropTable($this->table, true); } - protected function createTable() + protected function createTableForDefault() { $this->forge->dropTable($this->table, true); From a444ab1c45ab06a933066e502bdf36fe0be488bd Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 30 Jan 2024 10:12:43 +0900 Subject: [PATCH 4/5] test: move $this->createTableForDefault() to child classes --- tests/system/Database/Live/AbstractGetFieldDataTest.php | 1 - tests/system/Database/Live/MySQLi/GetFieldDataTest.php | 2 ++ tests/system/Database/Live/OCI8/GetFieldDataTest.php | 2 ++ tests/system/Database/Live/Postgre/GetFieldDataTest.php | 2 ++ tests/system/Database/Live/SQLSRV/GetFieldDataTest.php | 2 ++ tests/system/Database/Live/SQLite3/GetFieldDataTest.php | 2 ++ 6 files changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/system/Database/Live/AbstractGetFieldDataTest.php b/tests/system/Database/Live/AbstractGetFieldDataTest.php index 9d9eb89474e6..d52e3cf5adb1 100644 --- a/tests/system/Database/Live/AbstractGetFieldDataTest.php +++ b/tests/system/Database/Live/AbstractGetFieldDataTest.php @@ -35,7 +35,6 @@ protected function setUp(): void $this->db = Database::connect($this->DBGroup); $this->createForge(); - $this->createTableForDefault(); } /** diff --git a/tests/system/Database/Live/MySQLi/GetFieldDataTest.php b/tests/system/Database/Live/MySQLi/GetFieldDataTest.php index 547d45eace91..f48bc325a59a 100644 --- a/tests/system/Database/Live/MySQLi/GetFieldDataTest.php +++ b/tests/system/Database/Live/MySQLi/GetFieldDataTest.php @@ -48,6 +48,8 @@ private function isOldMySQL(): bool public function testGetFieldDataDefault(): void { + $this->createTableForDefault(); + $fields = $this->db->getFieldData($this->table); $this->assertJsonStringEqualsJsonString( diff --git a/tests/system/Database/Live/OCI8/GetFieldDataTest.php b/tests/system/Database/Live/OCI8/GetFieldDataTest.php index a6dc3156b248..ea733ea8b2ff 100644 --- a/tests/system/Database/Live/OCI8/GetFieldDataTest.php +++ b/tests/system/Database/Live/OCI8/GetFieldDataTest.php @@ -34,6 +34,8 @@ protected function createForge(): void public function testGetFieldDataDefault(): void { + $this->createTableForDefault(); + $fields = $this->db->getFieldData($this->table); $data = []; diff --git a/tests/system/Database/Live/Postgre/GetFieldDataTest.php b/tests/system/Database/Live/Postgre/GetFieldDataTest.php index ad62a7a38cb5..e891918343db 100644 --- a/tests/system/Database/Live/Postgre/GetFieldDataTest.php +++ b/tests/system/Database/Live/Postgre/GetFieldDataTest.php @@ -34,6 +34,8 @@ protected function createForge(): void public function testGetFieldDataDefault(): void { + $this->createTableForDefault(); + $fields = $this->db->getFieldData('test1'); $this->assertJsonStringEqualsJsonString( diff --git a/tests/system/Database/Live/SQLSRV/GetFieldDataTest.php b/tests/system/Database/Live/SQLSRV/GetFieldDataTest.php index 60d60577130c..b2b37741f27a 100644 --- a/tests/system/Database/Live/SQLSRV/GetFieldDataTest.php +++ b/tests/system/Database/Live/SQLSRV/GetFieldDataTest.php @@ -34,6 +34,8 @@ protected function createForge(): void public function testGetFieldDataDefault(): void { + $this->createTableForDefault(); + $fields = $this->db->getFieldData($this->table); $this->assertJsonStringEqualsJsonString( diff --git a/tests/system/Database/Live/SQLite3/GetFieldDataTest.php b/tests/system/Database/Live/SQLite3/GetFieldDataTest.php index 69cc9e01b7b2..00bc08e2cffd 100644 --- a/tests/system/Database/Live/SQLite3/GetFieldDataTest.php +++ b/tests/system/Database/Live/SQLite3/GetFieldDataTest.php @@ -38,6 +38,8 @@ protected function createForge(): void public function testGetFieldDataDefault(): void { + $this->createTableForDefault(); + $fields = $this->db->getFieldData($this->table); $this->assertJsonStringEqualsJsonString( From c271e1fb3b180d6b94150c86f2e17543ef321c38 Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 30 Jan 2024 10:53:09 +0900 Subject: [PATCH 5/5] test: add assertSameFieldData() --- .../Live/AbstractGetFieldDataTest.php | 13 ++ .../Database/Live/MySQLi/GetFieldDataTest.php | 120 ++++++------ .../Database/Live/OCI8/GetFieldDataTest.php | 13 +- .../Live/Postgre/GetFieldDataTest.php | 120 ++++++------ .../Database/Live/SQLSRV/GetFieldDataTest.php | 120 ++++++------ .../Live/SQLite3/GetFieldDataTest.php | 176 +++++++++--------- 6 files changed, 279 insertions(+), 283 deletions(-) diff --git a/tests/system/Database/Live/AbstractGetFieldDataTest.php b/tests/system/Database/Live/AbstractGetFieldDataTest.php index d52e3cf5adb1..859c37718902 100644 --- a/tests/system/Database/Live/AbstractGetFieldDataTest.php +++ b/tests/system/Database/Live/AbstractGetFieldDataTest.php @@ -92,4 +92,17 @@ protected function createTableForDefault() } abstract public function testGetFieldDataDefault(): void; + + protected function assertSameFieldData(array $expected, array $actual) + { + $expected = json_decode(json_encode($expected), true); + $names = array_column($expected, 'name'); + array_multisort($names, SORT_ASC, $expected); + + $fields = json_decode(json_encode($actual), true); + $names = array_column($fields, 'name'); + array_multisort($names, SORT_ASC, $fields); + + $this->assertSame($expected, $fields); + } } diff --git a/tests/system/Database/Live/MySQLi/GetFieldDataTest.php b/tests/system/Database/Live/MySQLi/GetFieldDataTest.php index f48bc325a59a..f5c9a0761ea4 100644 --- a/tests/system/Database/Live/MySQLi/GetFieldDataTest.php +++ b/tests/system/Database/Live/MySQLi/GetFieldDataTest.php @@ -52,66 +52,64 @@ public function testGetFieldDataDefault(): void $fields = $this->db->getFieldData($this->table); - $this->assertJsonStringEqualsJsonString( - json_encode([ - (object) [ - 'name' => 'id', - 'type' => 'int', - 'max_length' => $this->isOldMySQL() ? 11 : null, - 'default' => null, // The default value is not defined. - 'primary_key' => 1, - 'nullable' => false, - ], - (object) [ - 'name' => 'text_not_null', - 'type' => 'varchar', - 'max_length' => 64, - 'default' => null, // The default value is not defined. - 'primary_key' => 0, - 'nullable' => false, - ], - (object) [ - 'name' => 'text_null', - 'type' => 'varchar', - 'max_length' => 64, - 'default' => null, // The default value is not defined. - 'primary_key' => 0, - 'nullable' => true, - ], - (object) [ - 'name' => 'int_default_0', - 'type' => 'int', - 'max_length' => $this->isOldMySQL() ? 11 : null, - 'default' => '0', // int 0 - 'primary_key' => 0, - 'nullable' => false, - ], - (object) [ - 'name' => 'text_default_null', - 'type' => 'varchar', - 'max_length' => 64, - 'default' => null, // NULL value - 'primary_key' => 0, - 'nullable' => true, - ], - (object) [ - 'name' => 'text_default_text_null', - 'type' => 'varchar', - 'max_length' => 64, - 'default' => 'null', // string "null" - 'primary_key' => 0, - 'nullable' => false, - ], - (object) [ - 'name' => 'text_default_abc', - 'type' => 'varchar', - 'max_length' => 64, - 'default' => 'abc', // string "abc" - 'primary_key' => 0, - 'nullable' => false, - ], - ]), - json_encode($fields) - ); + $expected = [ + (object) [ + 'name' => 'id', + 'type' => 'int', + 'max_length' => $this->isOldMySQL() ? 11 : null, + 'nullable' => false, + 'default' => null, // The default value is not defined. + 'primary_key' => 1, + ], + (object) [ + 'name' => 'text_not_null', + 'type' => 'varchar', + 'max_length' => 64, + 'nullable' => false, + 'default' => null, // The default value is not defined. + 'primary_key' => 0, + ], + (object) [ + 'name' => 'text_null', + 'type' => 'varchar', + 'max_length' => 64, + 'nullable' => true, + 'default' => null, // The default value is not defined. + 'primary_key' => 0, + ], + (object) [ + 'name' => 'int_default_0', + 'type' => 'int', + 'max_length' => $this->isOldMySQL() ? 11 : null, + 'nullable' => false, + 'default' => '0', // int 0 + 'primary_key' => 0, + ], + (object) [ + 'name' => 'text_default_null', + 'type' => 'varchar', + 'max_length' => 64, + 'nullable' => true, + 'default' => null, // NULL value + 'primary_key' => 0, + ], + (object) [ + 'name' => 'text_default_text_null', + 'type' => 'varchar', + 'max_length' => 64, + 'nullable' => false, + 'default' => 'null', // string "null" + 'primary_key' => 0, + ], + (object) [ + 'name' => 'text_default_abc', + 'type' => 'varchar', + 'max_length' => 64, + 'nullable' => false, + 'default' => 'abc', // string "abc" + 'primary_key' => 0, + ], + ]; + $this->assertSameFieldData($expected, $fields); } } diff --git a/tests/system/Database/Live/OCI8/GetFieldDataTest.php b/tests/system/Database/Live/OCI8/GetFieldDataTest.php index ea733ea8b2ff..89750fd60bf8 100644 --- a/tests/system/Database/Live/OCI8/GetFieldDataTest.php +++ b/tests/system/Database/Live/OCI8/GetFieldDataTest.php @@ -47,7 +47,7 @@ public function testGetFieldDataDefault(): void $idDefault = $data['id']->default; $this->assertMatchesRegularExpression('/"ORACLE"."ISEQ\$\$_[0-9]+".nextval/', $idDefault); - $expected = json_decode(json_encode([ + $expected = [ (object) [ 'name' => 'id', 'type' => 'NUMBER', @@ -104,14 +104,7 @@ public function testGetFieldDataDefault(): void 'default' => "'abc' ", // string "abc" // 'primary_key' => 0, ], - ]), true); - $names = array_column($expected, 'name'); - array_multisort($names, SORT_ASC, $expected); - - $fields = json_decode(json_encode($fields), true); - $names = array_column($fields, 'name'); - array_multisort($names, SORT_ASC, $fields); - - $this->assertSame($expected, $fields); + ]; + $this->assertSameFieldData($expected, $fields); } } diff --git a/tests/system/Database/Live/Postgre/GetFieldDataTest.php b/tests/system/Database/Live/Postgre/GetFieldDataTest.php index e891918343db..514bb7011c74 100644 --- a/tests/system/Database/Live/Postgre/GetFieldDataTest.php +++ b/tests/system/Database/Live/Postgre/GetFieldDataTest.php @@ -38,66 +38,64 @@ public function testGetFieldDataDefault(): void $fields = $this->db->getFieldData('test1'); - $this->assertJsonStringEqualsJsonString( - json_encode([ - (object) [ - 'name' => 'id', - 'type' => 'integer', - 'max_length' => '32', - 'default' => "nextval('db_test1_id_seq'::regclass)", // The default value is not defined. - // 'primary_key' => 1, - 'nullable' => false, - ], - (object) [ - 'name' => 'text_not_null', - 'type' => 'character varying', - 'max_length' => '64', - 'default' => null, // The default value is not defined. - // 'primary_key' => 0, - 'nullable' => false, - ], - (object) [ - 'name' => 'text_null', - 'type' => 'character varying', - 'max_length' => '64', - 'default' => null, // The default value is not defined. - // 'primary_key' => 0, - 'nullable' => true, - ], - (object) [ - 'name' => 'int_default_0', - 'type' => 'integer', - 'max_length' => '32', - 'default' => '0', // int 0 - // 'primary_key' => 0, - 'nullable' => false, - ], - (object) [ - 'name' => 'text_default_null', - 'type' => 'character varying', - 'max_length' => '64', - 'default' => 'NULL::character varying', // NULL value - // 'primary_key' => 0, - 'nullable' => true, - ], - (object) [ - 'name' => 'text_default_text_null', - 'type' => 'character varying', - 'max_length' => '64', - 'default' => "'null'::character varying", // string "null" - // 'primary_key' => 0, - 'nullable' => false, - ], - (object) [ - 'name' => 'text_default_abc', - 'type' => 'character varying', - 'max_length' => '64', - 'default' => "'abc'::character varying", // string "abc" - // 'primary_key' => 0, - 'nullable' => false, - ], - ]), - json_encode($fields) - ); + $expected = [ + (object) [ + 'name' => 'id', + 'type' => 'integer', + 'max_length' => '32', + 'nullable' => false, + // 'primary_key' => 1, + 'default' => "nextval('db_test1_id_seq'::regclass)", // The default value is not defined. + ], + (object) [ + 'name' => 'text_not_null', + 'type' => 'character varying', + 'max_length' => '64', + 'nullable' => false, + // 'primary_key' => 0, + 'default' => null, // The default value is not defined. + ], + (object) [ + 'name' => 'text_null', + 'type' => 'character varying', + 'max_length' => '64', + 'nullable' => true, + // 'primary_key' => 0, + 'default' => null, // The default value is not defined. + ], + (object) [ + 'name' => 'int_default_0', + 'type' => 'integer', + 'max_length' => '32', + 'nullable' => false, + // 'primary_key' => 0, + 'default' => '0', // int 0 + ], + (object) [ + 'name' => 'text_default_null', + 'type' => 'character varying', + 'max_length' => '64', + 'nullable' => true, + // 'primary_key' => 0, + 'default' => 'NULL::character varying', // NULL value + ], + (object) [ + 'name' => 'text_default_text_null', + 'type' => 'character varying', + 'max_length' => '64', + 'nullable' => false, + // 'primary_key' => 0, + 'default' => "'null'::character varying", // string "null" + ], + (object) [ + 'name' => 'text_default_abc', + 'type' => 'character varying', + 'max_length' => '64', + 'nullable' => false, + // 'primary_key' => 0, + 'default' => "'abc'::character varying", // string "abc" + ], + ]; + $this->assertSameFieldData($expected, $fields); } } diff --git a/tests/system/Database/Live/SQLSRV/GetFieldDataTest.php b/tests/system/Database/Live/SQLSRV/GetFieldDataTest.php index b2b37741f27a..ada673292ddd 100644 --- a/tests/system/Database/Live/SQLSRV/GetFieldDataTest.php +++ b/tests/system/Database/Live/SQLSRV/GetFieldDataTest.php @@ -38,66 +38,64 @@ public function testGetFieldDataDefault(): void $fields = $this->db->getFieldData($this->table); - $this->assertJsonStringEqualsJsonString( - json_encode([ - (object) [ - 'name' => 'id', - 'type' => 'int', - 'max_length' => 10, - 'default' => null, // The default value is not defined. - // 'primary_key' => 1, - 'nullable' => false, - ], - (object) [ - 'name' => 'text_not_null', - 'type' => 'varchar', - 'max_length' => 64, - 'default' => null, // The default value is not defined. - // 'primary_key' => 0, - 'nullable' => false, - ], - (object) [ - 'name' => 'text_null', - 'type' => 'varchar', - 'max_length' => 64, - 'default' => null, // The default value is not defined. - // 'primary_key' => 0, - 'nullable' => true, - ], - (object) [ - 'name' => 'int_default_0', - 'type' => 'int', - 'max_length' => 10, - 'default' => '((0))', // int 0 - // 'primary_key' => 0, - 'nullable' => false, - ], - (object) [ - 'name' => 'text_default_null', - 'type' => 'varchar', - 'max_length' => 64, - 'default' => '(NULL)', // NULL value - // 'primary_key' => 0, - 'nullable' => true, - ], - (object) [ - 'name' => 'text_default_text_null', - 'type' => 'varchar', - 'max_length' => 64, - 'default' => "('null')", // string "null" - // 'primary_key' => 0, - 'nullable' => false, - ], - (object) [ - 'name' => 'text_default_abc', - 'type' => 'varchar', - 'max_length' => 64, - 'default' => "('abc')", // string "abc" - // 'primary_key' => 0, - 'nullable' => false, - ], - ]), - json_encode($fields) - ); + $expected = [ + (object) [ + 'name' => 'id', + 'type' => 'int', + 'max_length' => 10, + 'nullable' => false, + 'default' => null, // The default value is not defined. + // 'primary_key' => 1, + ], + (object) [ + 'name' => 'text_not_null', + 'type' => 'varchar', + 'max_length' => 64, + 'nullable' => false, + 'default' => null, // The default value is not defined. + // 'primary_key' => 0, + ], + (object) [ + 'name' => 'text_null', + 'type' => 'varchar', + 'max_length' => 64, + 'nullable' => true, + 'default' => null, // The default value is not defined. + // 'primary_key' => 0, + ], + (object) [ + 'name' => 'int_default_0', + 'type' => 'int', + 'max_length' => 10, + 'nullable' => false, + 'default' => '((0))', // int 0 + // 'primary_key' => 0, + ], + (object) [ + 'name' => 'text_default_null', + 'type' => 'varchar', + 'max_length' => 64, + 'nullable' => true, + 'default' => '(NULL)', // NULL value + // 'primary_key' => 0, + ], + (object) [ + 'name' => 'text_default_text_null', + 'type' => 'varchar', + 'max_length' => 64, + 'nullable' => false, + 'default' => "('null')", // string "null" + // 'primary_key' => 0, + ], + (object) [ + 'name' => 'text_default_abc', + 'type' => 'varchar', + 'max_length' => 64, + 'nullable' => false, + 'default' => "('abc')", // string "abc" + // 'primary_key' => 0, + ], + ]; + $this->assertSameFieldData($expected, $fields); } } diff --git a/tests/system/Database/Live/SQLite3/GetFieldDataTest.php b/tests/system/Database/Live/SQLite3/GetFieldDataTest.php index 00bc08e2cffd..2f14d2f60ba4 100644 --- a/tests/system/Database/Live/SQLite3/GetFieldDataTest.php +++ b/tests/system/Database/Live/SQLite3/GetFieldDataTest.php @@ -42,67 +42,65 @@ public function testGetFieldDataDefault(): void $fields = $this->db->getFieldData($this->table); - $this->assertJsonStringEqualsJsonString( - json_encode([ - (object) [ - 'name' => 'id', - 'type' => 'INTEGER', - 'max_length' => null, - 'default' => null, // The default value is not defined. - 'primary_key' => 1, - 'nullable' => true, - ], - (object) [ - 'name' => 'text_not_null', - 'type' => 'VARCHAR', - 'max_length' => null, - 'default' => null, // The default value is not defined. - 'primary_key' => 0, - 'nullable' => false, - ], - (object) [ - 'name' => 'text_null', - 'type' => 'VARCHAR', - 'max_length' => null, - 'default' => null, // The default value is not defined. - 'primary_key' => 0, - 'nullable' => true, - ], - (object) [ - 'name' => 'int_default_0', - 'type' => 'INT', - 'max_length' => null, - 'default' => '0', // int 0 - 'primary_key' => 0, - 'nullable' => false, - ], - (object) [ - 'name' => 'text_default_null', - 'type' => 'VARCHAR', - 'max_length' => null, - 'default' => 'NULL', // NULL value - 'primary_key' => 0, - 'nullable' => true, - ], - (object) [ - 'name' => 'text_default_text_null', - 'type' => 'VARCHAR', - 'max_length' => null, - 'default' => "'null'", // string "null" - 'primary_key' => 0, - 'nullable' => false, - ], - (object) [ - 'name' => 'text_default_abc', - 'type' => 'VARCHAR', - 'max_length' => null, - 'default' => "'abc'", // string "abc" - 'primary_key' => 0, - 'nullable' => false, - ], - ]), - json_encode($fields) - ); + $expected = [ + (object) [ + 'name' => 'id', + 'type' => 'INTEGER', + 'max_length' => null, + 'nullable' => true, + 'default' => null, // The default value is not defined. + 'primary_key' => 1, + ], + (object) [ + 'name' => 'text_not_null', + 'type' => 'VARCHAR', + 'max_length' => null, + 'nullable' => false, + 'default' => null, // The default value is not defined. + 'primary_key' => 0, + ], + (object) [ + 'name' => 'text_null', + 'type' => 'VARCHAR', + 'max_length' => null, + 'nullable' => true, + 'default' => null, // The default value is not defined. + 'primary_key' => 0, + ], + (object) [ + 'name' => 'int_default_0', + 'type' => 'INT', + 'max_length' => null, + 'nullable' => false, + 'default' => '0', // int 0 + 'primary_key' => 0, + ], + (object) [ + 'name' => 'text_default_null', + 'type' => 'VARCHAR', + 'max_length' => null, + 'nullable' => true, + 'default' => 'NULL', // NULL value + 'primary_key' => 0, + ], + (object) [ + 'name' => 'text_default_text_null', + 'type' => 'VARCHAR', + 'max_length' => null, + 'nullable' => false, + 'default' => "'null'", // string "null" + 'primary_key' => 0, + ], + (object) [ + 'name' => 'text_default_abc', + 'type' => 'VARCHAR', + 'max_length' => null, + 'nullable' => false, + 'default' => "'abc'", // string "abc" + 'primary_key' => 0, + ], + ]; + $this->assertSameFieldData($expected, $fields); } protected function createTableCompositePrimaryKey() @@ -133,34 +131,32 @@ public function testGetFieldDataCompositePrimaryKey(): void $fields = $this->db->getFieldData($this->table); - $this->assertJsonStringEqualsJsonString( - json_encode([ - (object) [ - 'name' => 'pk1', - 'type' => 'VARCHAR', - 'max_length' => null, - 'default' => null, - 'primary_key' => 1, - 'nullable' => false, - ], - (object) [ - 'name' => 'pk2', - 'type' => 'VARCHAR', - 'max_length' => null, - 'default' => null, - 'primary_key' => 1, - 'nullable' => false, - ], - (object) [ - 'name' => 'text', - 'type' => 'VARCHAR', - 'max_length' => null, - 'default' => null, - 'primary_key' => 0, - 'nullable' => false, - ], - ]), - json_encode($fields) - ); + $expected = [ + (object) [ + 'name' => 'pk1', + 'type' => 'VARCHAR', + 'max_length' => null, + 'nullable' => false, + 'default' => null, + 'primary_key' => 1, + ], + (object) [ + 'name' => 'pk2', + 'type' => 'VARCHAR', + 'max_length' => null, + 'nullable' => false, + 'default' => null, + 'primary_key' => 1, + ], + (object) [ + 'name' => 'text', + 'type' => 'VARCHAR', + 'max_length' => null, + 'nullable' => false, + 'default' => null, + 'primary_key' => 0, + ], + ]; + $this->assertSameFieldData($expected, $fields); } }