Commit a6286d5a authored by Nick Sellen's avatar Nick Sellen

Set utf8mb4 in a few more places and add a test

parent 66ece969
......@@ -26,24 +26,24 @@ modules:
config:
Db:
# http://codeception.com/docs/modules/Db
dsn: mysql:host=db;dbname=foodsharing
dsn: mysql:host=db;dbname=foodsharing;charset=utf8mb4
user: root
password: root
cleanup: true
populator: 'mysql -u$user -h$host -p$password $dbname < migrations/_reload_data.sql'
\Helper\Foodsharing:
# custom module that inherits from Db so also needs db config
dsn: mysql:host=db;dbname=foodsharing
dsn: mysql:host=db;dbname=foodsharing;charset=utf8mb4
user: root
password: root
\Helper\FoodsharingUrl:
# custom module that inherits from Db so also needs db config
dsn: mysql:host=db;dbname=foodsharing
dsn: mysql:host=db;dbname=foodsharing;charset=utf8mb4
user: root
password: root
\Helper\Container:
# custom module that inherits from Db so also needs db config
dsn: mysql:host=db;dbname=foodsharing
dsn: mysql:host=db;dbname=foodsharing;charset=utf8mb4
user: root
password: root
host: db
......
......@@ -60,4 +60,4 @@ define('CNT_BOTTOM', 3);
define('CNT_LEFT', 4);
define('CNT_OVERTOP', 5);
define('DSN', 'mysql:host=' . DB_HOST . ';dbname=' . DB_DB . ';charset=utf8');
define('DSN', 'mysql:host=' . DB_HOST . ';dbname=' . DB_DB . ';charset=utf8mb4');
......@@ -129,6 +129,7 @@ services:
- !php/const DB_DB
calls:
- [query, ['SET NAMES "utf8mb4"']]
PDO:
class: PDO
arguments:
......@@ -138,7 +139,6 @@ services:
calls:
- [ setAttribute, [!php/const PDO::ATTR_EMULATE_PREPARES, false]]
- [ setAttribute, [!php/const PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION]]
- [ setAttribute, [!php/const PDO::MYSQL_ATTR_INIT_COMMAND, 'SET NAMES "utf8mb4"']]
InfluxDB\Database:
factory: ['InfluxDB\Client', 'fromdsn']
......
......@@ -107,7 +107,7 @@ services:
db:
container_name: foodsharing_dev_db
image: registry.gitlab.com/foodsharing-dev/images/db/dev:1.0
image: registry.gitlab.com/foodsharing-dev/images/db/dev:1.1
# so we can mount tmpfs inside container
privileged: true
expose:
......
......@@ -100,7 +100,7 @@ services:
db:
container_name: foodsharing_test_db
image: registry.gitlab.com/foodsharing-dev/images/db/test:1.0
image: registry.gitlab.com/foodsharing-dev/images/db/test:1.1
# so we can mount tmpfs inside container
privileged: true
expose:
......
<?php
class EmojiTest extends \Codeception\Test\Unit
{
/**
* @var \UnitTester
*/
protected $tester;
/**
* @var \Foodsharing\Modules\Core\Database
*/
private $db;
/**
* @var \Foodsharing\Lib\Db\Db
*/
private $db2;
private $user1;
private $user2;
private $conversation;
private $messageBody;
private $messageId;
protected function _before()
{
$this->db = $this->tester->get(\Foodsharing\Modules\Core\Database::class);
$this->db2 = $this->tester->get(\Foodsharing\Lib\Db\Db::class);
$this->user1 = $this->tester->createFoodsharer();
$this->user2 = $this->tester->createFoodsharer();
$this->conversation = $this->tester->createConversation([
$this->user1['id'],
$this->user2['id']
]);
$this->messageBody = 'Hey dude 😂! You are such a ★ :)';
$this->messageId = $this->db->insert('fs_msg', [
'conversation_id' => $this->conversation['id'],
'foodsaver_id' => $this->user1['id'],
'body' => $this->messageBody,
'time' => $this->db->now()
]);
}
public function testEmojiHandlingWithPDO()
{
$body = $this->db->fetchValueByCriteria('fs_msg', 'body', ['id' => $this->messageId]);
$this->assertEquals($this->messageBody, $body);
}
public function testEmojiHandlingWithMysqli()
{
$body = $this->db2->qOne('select body from fs_msg where id = ' . $this->messageId);
$this->assertEquals($this->messageBody, $body);
}
public function testEmojiHandlingWithCodeceptionDB()
{
$body = $this->tester->grabColumnFromDatabase('fs_msg', 'body', ['id' => $this->messageId])[0];
$this->assertEquals($this->messageBody, $body);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment