Skip to content

test: add tests for getFieldData() type - #8482

Merged
kenjis merged 1 commit into
codeigniter4:developfrom
kenjis:test-add-getFieldData-type
Feb 10, 2024
Merged

kenjis merged 1 commit into
codeigniter4:developfrom
kenjis:test-add-getFieldData-type

Conversation

@kenjis

@kenjis kenjis commented Jan 30, 2024

Copy link
Copy Markdown
Member

Needs #8480

Description

  • add tests for the current behaviors

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjis kenjis added the testing Pull requests that changes tests only label Jan 30, 2024
@kenjis
kenjis marked this pull request as draft January 30, 2024 08:03
@kenjis
kenjis force-pushed the test-add-getFieldData-type branch 2 times, most recently from 1954e71 to 3df8961 Compare January 30, 2024 08:25
@kenjis

kenjis commented Jan 30, 2024

Copy link
Copy Markdown
Member Author

I've found there are two getFieldData() methods.
It is documented in https://codeigniter4.github.io/CodeIgniter4/database/metadata.html#db-getfielddata

--- a/tests/system/Database/Live/MySQLi/GetFieldDataTest.php
+++ b/tests/system/Database/Live/MySQLi/GetFieldDataTest.php
@@ -117,7 +117,7 @@ final class GetFieldDataTest extends AbstractGetFieldDataTest
     {
         $this->createTableForType();
 
-        $fields = $this->db->getFieldData($this->table);
+        $fields = $this->db->table($this->table)->get()->getFieldData();
 
         $expected = [
             0 => (object) [

But ResultInterface::getFieldData() returns different data.

$ vendor/bin/phpunit tests/system/Database/Live/MySQLi/GetFieldDataTest.php
PHPUnit 9.6.16 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.2.15
Configuration: /Users/kenji/work/codeigniter/official/CodeIgniter4/phpunit.xml

.F                                                                                          2 / 2 (100%)

Time: 00:00.735, Memory: 18.00 MB

There was 1 failure:

1) CodeIgniter\Database\Live\MySQLi\GetFieldDataTest::testGetFieldDataType
Failed asserting that two arrays are identical.
--- Expected
+++ Actual
@@ @@
 Array &0 (
     0 => Array &1 (
         'name' => 'id'
-        'type' => 'int'
-        'max_length' => null
-        'nullable' => false
-        'default' => null
-        'primary_key' => 1
+        'type' => 3
+        'type_name' => 'long'
+        'max_length' => 0
+        'primary_key' => 2
+        'length' => 20
+        'default' => ''
     )
     1 => Array &2 (
         'name' => 'type_bigint'
-        'type' => 'bigint'
-        'max_length' => null
-        'nullable' => true
-        'default' => null
+        'type' => 8
+        'type_name' => 'longlong'
+        'max_length' => 0
         'primary_key' => 0
+        'length' => 20
+        'default' => ''
     )
     2 => Array &3 (
         'name' => 'type_blob'
-        'type' => 'blob'
-        'max_length' => null
-        'nullable' => true
-        'default' => null
+        'type' => 252
+        'type_name' => 'blob'
+        'max_length' => 0
         'primary_key' => 0
+        'length' => 65535
+        'default' => ''
     )
     3 => Array &4 (
         'name' => 'type_boolean'
-        'type' => 'tinyint'
-        'max_length' => 1
-        'nullable' => true
-        'default' => null
+        'type' => 1
+        'type_name' => 'char'
+        'max_length' => 0
         'primary_key' => 0
+        'length' => 1
+        'default' => ''
     )
     4 => Array &5 (
         'name' => 'type_char'
-        'type' => 'char'
-        'max_length' => 10
-        'nullable' => true
-        'default' => null
+        'type' => 254
+        'type_name' => 'string'
+        'max_length' => 0
         'primary_key' => 0
+        'length' => 30
+        'default' => ''
     )
     5 => Array &6 (
         'name' => 'type_date'
-        'type' => 'date'
-        'max_length' => null
-        'nullable' => true
-        'default' => null
+        'type' => 10
+        'type_name' => 'date'
+        'max_length' => 0
         'primary_key' => 0
+        'length' => 10
+        'default' => ''
     )
     6 => Array &7 (
         'name' => 'type_datetime'
-        'type' => 'datetime'
-        'max_length' => null
-        'nullable' => true
-        'default' => null
+        'type' => 12
+        'type_name' => 'datetime'
+        'max_length' => 0
         'primary_key' => 0
+        'length' => 19
+        'default' => ''
     )
     7 => Array &8 (
         'name' => 'type_decimal'
-        'type' => 'decimal'
-        'max_length' => 18
-        'nullable' => true
-        'default' => null
+        'type' => 246
+        'type_name' => 'newdecimal'
+        'max_length' => 0
         'primary_key' => 0
+        'length' => 20
+        'default' => ''
     )
     8 => Array &9 (
         'name' => 'type_double'
-        'type' => 'double'
-        'max_length' => null
-        'nullable' => true
-        'default' => null
+        'type' => 5
+        'type_name' => 'double'
+        'max_length' => 0
         'primary_key' => 0
+        'length' => 22
+        'default' => ''
     )
     9 => Array &10 (
         'name' => 'type_enum'
-        'type' => 'enum'
-        'max_length' => null
-        'nullable' => true
-        'default' => null
+        'type' => 254
+        'type_name' => 'string'
+        'max_length' => 0
         'primary_key' => 0
+        'length' => 15
+        'default' => ''
     )
     10 => Array &11 (
         'name' => 'type_float'
-        'type' => 'float'
-        'max_length' => null
-        'nullable' => true
-        'default' => null
+        'type' => 4
+        'type_name' => 'float'
+        'max_length' => 0
         'primary_key' => 0
+        'length' => 12
+        'default' => ''
     )
     11 => Array &12 (
         'name' => 'type_integer'
-        'type' => 'int'
-        'max_length' => null
-        'nullable' => true
-        'default' => null
+        'type' => 3
+        'type_name' => 'long'
+        'max_length' => 0
         'primary_key' => 0
+        'length' => 11
+        'default' => ''
     )
     12 => Array &13 (
         'name' => 'type_mediumtext'
-        'type' => 'mediumtext'
-        'max_length' => null
-        'nullable' => true
-        'default' => null
+        'type' => 252
+        'type_name' => 'blob'
+        'max_length' => 0
         'primary_key' => 0
+        'length' => 50331645
+        'default' => ''
     )
     13 => Array &14 (
         'name' => 'type_numeric'
-        'type' => 'decimal'
-        'max_length' => 18
-        'nullable' => true
-        'default' => null
+        'type' => 246
+        'type_name' => 'newdecimal'
+        'max_length' => 0
         'primary_key' => 0
+        'length' => 20
+        'default' => ''
     )
     14 => Array &15 (
         'name' => 'type_real'
-        'type' => 'double'
-        'max_length' => null
-        'nullable' => true
-        'default' => null
+        'type' => 5
+        'type_name' => 'double'
+        'max_length' => 0
         'primary_key' => 0
+        'length' => 22
+        'default' => ''
     )
     15 => Array &16 (
         'name' => 'type_set'
-        'type' => 'set'
-        'max_length' => null
-        'nullable' => true
-        'default' => null
+        'type' => 254
+        'type_name' => 'string'
+        'max_length' => 0
         'primary_key' => 0
+        'length' => 21
+        'default' => ''
     )
     16 => Array &17 (
         'name' => 'type_smallint'
-        'type' => 'smallint'
-        'max_length' => null
-        'nullable' => true
-        'default' => null
+        'type' => 2
+        'type_name' => 'short'
+        'max_length' => 0
         'primary_key' => 0
+        'length' => 6
+        'default' => ''
     )
     17 => Array &18 (
         'name' => 'type_text'
-        'type' => 'text'
-        'max_length' => null
-        'nullable' => true
-        'default' => null
+        'type' => 252
+        'type_name' => 'blob'
+        'max_length' => 0
         'primary_key' => 0
+        'length' => 196605
+        'default' => ''
     )
     18 => Array &19 (
         'name' => 'type_time'
-        'type' => 'time'
-        'max_length' => null
-        'nullable' => true
-        'default' => null
+        'type' => 11
+        'type_name' => 'time'
+        'max_length' => 0
         'primary_key' => 0
+        'length' => 10
+        'default' => ''
     )
     19 => Array &20 (
         'name' => 'type_timestamp'
-        'type' => 'timestamp'
-        'max_length' => null
-        'nullable' => true
-        'default' => null
+        'type' => 7
+        'type_name' => 'timestamp'
+        'max_length' => 0
         'primary_key' => 0
+        'length' => 19
+        'default' => ''
     )
     20 => Array &21 (
         'name' => 'type_varchar'
-        'type' => 'varchar'
-        'max_length' => 40
-        'nullable' => true
-        'default' => null
+        'type' => 253
+        'type_name' => 'var_string'
+        'max_length' => 0
         'primary_key' => 0
+        'length' => 120
+        'default' => ''
     )
 )
...

@kenjis
kenjis force-pushed the test-add-getFieldData-type branch from 3df8961 to c4de4f9 Compare February 1, 2024 00:08
@kenjis
kenjis marked this pull request as ready for review February 1, 2024 00:08
@kenjis

kenjis commented Feb 4, 2024

Copy link
Copy Markdown
Member Author

Can someone approve?

@kenjis
kenjis merged commit af5d5df into codeigniter4:develop Feb 10, 2024
@kenjis
kenjis deleted the test-add-getFieldData-type branch February 10, 2024 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing Pull requests that changes tests only

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants