Add 'timezone' config support for Db model
What are you trying to achieve?
Specific timezone when use Db Model connect to mysql , then the test logic won't rely on database config.
What do you get instead?
Can't achieve this for now.
Provide console output if related. Use
-vvvmode for more details.
# paste output here
Provide test source code if related
// paste test
Details
- Codeception version:
- PHP Version:
- Operating System:
- Installation type: Phar || Composer
- List of installed packages (
composer show) - Suite configuration:
# paste suite config here
Try to add timezone to dump.sql
For example "headers" of mysqldump contain someone like this (see last line of example)
-- MySQL dump 10.13 Distrib 8.0.3-rc, for Linux (x86_64)
...
-- ------------------------------------------------------
-- Server version 8.0.3-rc-log
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
SET NAMES utf8mb4 ;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
@bscheshirwork Sounds a good solution , but I think timezone is an important property in a database connection , Db model should have the ability to control it.
timezone is an important property in a database connection
So... Example for PDO connect, please? (without test case)
For now I add the method below in my Actor class,And call this method before each test
use \Codeception\Module\Db;
public function customDbModelTimezone(Db $Db){
$Dbtimezone = $Db->_getConfig('timezone');
if (!is_null($Dbtimezone)) {
$pdo = $Db->dbh;
switch ($pdo->getAttribute(PDO::ATTR_DRIVER_NAME)) {
case 'mysql':
$pdo->prepare('set time_zone="'.$Dbtimezone.'"')->execute();
break;
default:
break;
}
}
}
my Db Model config like this
modules:
config:
Db:
dsn: 'mysql:host=HOST;dbname=DBNAME'
user: USERNAME
password: PASSWD
populate: true
timezone: '+8:00'
dump: tests/_data/dump.sql
If you think it's important you can send Pull Request