0
votes

i got some problems with Dbh module in Codeception. First of all, i wanna rollback every db operations in each test (after seeInDatabase of course). So my codeception.yml is

paths:
    tests: tests
    log: tests/_log
    data: tests/_data
    helpers: tests/_helpers
settings:
    bootstrap: _bootstrap.php
    suite_class: \PHPUnit_Framework_TestSuite
    memory_limit: 1024M
    log: true
    colors: true
coverage:
    enabled: true
    remote: true
    include:
        - controllers/*
        - models/*
        - widgets/*
modules:
    enabled: [Db,Dbh]
    config:
        Db:
            dsn: 'mysql:host=localhost;dbname=baxi'
            user: 'root'
            password: ''
            #dump: tests/_data/dump.sql
            cleanup: true
        Dbh:
            cleanup: false

After that guide says put this in bootstrap

<?php
 \Codeception\Module\Dbh::$dbh = $dbh;
 ?>

But how can i get $dbh from Db module? At the end i get error

[Codeception\Exception\ModuleConfig]                      
  Dbh module is not configured!                             

  Transaction module requires PDO instance explicitly set.  
  You can use your bootstrap file to assign the dbh:        

  \Codeception\Module\Dbh::$dbh = $dbh  

How to setup this correctly?

2

2 Answers

0
votes

Maybe you need to do something like this in your bootstrap file:

$dbh = new PDO('mysql:host=localhost;dbname=baxi;charset=utf8', 'root', '');
\Codeception\Module\Dbh::$dbh = $dbh;
0
votes

You can also use config params from your codeception.yml:

\Codeception\Module\Dbh::$dbh = new PDO($settings['modules']['config']['Db']['dsn'], $settings['modules']['config']['Db']['user'], $settings['modules']['config']['Db']['password']);