Codeception / module-db

DB module for Codeception
MIT License
23 stars 24 forks source link

[JsonException] Malformed UTF-8 characters, possibly incorrectly encoded #47

Open cybd opened 1 year ago

cybd commented 1 year ago

I'm using UUID as binary(16) in MySQL tables. My test is failed when I'm trying to test seeInDatabase using UUID as filter criteria.

Test failed with error: [JsonException] Malformed UTF-8 characters, possibly incorrectly encoded

php vendor/bin/codecept run unit Codeception/Module/Db/MySqlDbTest:testSeeInDatabaseWithBinary -vvv

Console output with -vvv mode:

Codeception PHP Testing Framework v5.0.10 https://helpukrainewin.org

  actor is empty

Unit Tests (1) --------------------------------------------------------------------------------------------------------------------------------------------------------------
Modules: 
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- MySqlDbTest: See in database with binary  [Connecting To Db] {"config":{"populate":true,"cleanup":true,"reconnect":true,"waitlock":0,"dump":"tests/data/dumps/mysql.sql","populator":null,"skip_cleanup_if_failed":false,"dsn":"mysql:host=host.docker.internal;port=3102;dbname=codeception","user":"root","password":"codeception"},"options":[]}
  [Db] Connected to default codeception
  [Db] Disconnected from default
  [Connecting To Db] {"config":{"populate":true,"cleanup":true,"reconnect":true,"waitlock":0,"dump":"tests/data/dumps/mysql.sql","populator":null,"skip_cleanup_if_failed":false,"dsn":"mysql:host=host.docker.internal;port=3102;dbname=codeception","user":"root","password":"codeception"},"options":[]}
  [Db] Connected to default codeception
  [Query] SELECT count(*) FROM `users` WHERE `uuid` = ? 
  [Parameters] ["u0011ufffdufffdKu0001ufffdrufffdufffdu001du0002Bufffdu0012u0000u0006"]
E MySqlDbTest: See in database with binary(0.19s)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Time: 00:00.213, Memory: 12.00 MB

There was 1 error:
1) MySqlDbTest: See in database with binary
 Test  tests/unit/Codeception/Module/Db/MySqlDbTest.php:testSeeInDatabaseWithBinary

  [JsonException] Malformed UTF-8 characters, possibly incorrectly encoded  

/var/www/html/src/Codeception/Module/Db.php:839
/var/www/html/tests/unit/Codeception/Module/Db/AbstractDbTest.php:69
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestCase.php:1067
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestCase.php:634
/var/www/html/vendor/codeception/codeception/src/Codeception/Test/TestCaseWrapper.php:148
/var/www/html/vendor/codeception/codeception/src/Codeception/Test/Test.php:170
/var/www/html/vendor/codeception/codeception/src/Codeception/Suite.php:130
/var/www/html/vendor/codeception/codeception/src/Codeception/SuiteManager.php:148
/var/www/html/vendor/codeception/codeception/src/Codeception/Codecept.php:260
/var/www/html/vendor/codeception/codeception/src/Codeception/Codecept.php:216
/var/www/html/vendor/codeception/codeception/src/Codeception/Command/Run.php:435
/var/www/html/vendor/symfony/console/Command/Command.php:326
/var/www/html/vendor/symfony/console/Application.php:1063
/var/www/html/vendor/symfony/console/Application.php:320
/var/www/html/vendor/symfony/console/Application.php:174
/var/www/html/vendor/codeception/codeception/src/Codeception/Application.php:112
/var/www/html/vendor/codeception/codeception/app.php:45
/var/www/html/vendor/codeception/codeception/app.php:46
/var/www/html/vendor/codeception/codeception/codecept:7
/var/www/html/vendor/bin/codecept:120

ERRORS!
Tests: 1, Assertions: 1, Errors: 1.
  [Db] Disconnected from default

Provide test source code if related

CREATE TABLE `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `uuid` binary(16) DEFAULT NULL,
  `name` varchar(30) DEFAULT NULL,
  `email` varchar(255) DEFAULT NULL,
  `is_active` bit(1) DEFAULT b'1',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

insert  into `users`(`id`,`uuid`, `name`,`email`, `is_active`,`created_at`) values (1,0x11edc34b01d972fa9c1d0242ac120006,'davert','davert@mail.ua', b'1','2012-02-01 21:17:04');
    public function testSeeInDatabaseWithBinary()
    {
        $this->module->seeInDatabase('users', ['uuid' => hex2bin('11edc34b01d972fa9c1d0242ac120006')]);
    }

Details