Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'timezone' config support for Db model #16

Open
xieqiaoyu opened this issue Jan 17, 2018 · 5 comments
Open

Add 'timezone' config support for Db model #16

xieqiaoyu opened this issue Jan 17, 2018 · 5 comments

Comments

@xieqiaoyu
Copy link

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 -vvv mode 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
@bscheshirwork
Copy link

bscheshirwork commented Jan 18, 2018

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' */;

@xieqiaoyu
Copy link
Author

@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.

@bscheshirwork
Copy link

timezone is an important property in a database connection

So... Example for PDO connect, please? (without test case)

@xieqiaoyu
Copy link
Author

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

@DavertMik
Copy link
Member

If you think it's important you can send Pull Request

@Naktibalda Naktibalda transferred this issue from Codeception/Codeception Jan 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants