Codeception / module-db

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

I get error message: codecept [PHPUnit\Framework\Error\Notice] Undefined index: default #36

Closed FirasSahli2010 closed 2 years ago

FirasSahli2010 commented 2 years ago

Hello everyone, When running my unit test I get an error message saying [PHPUnit\Framework\Error\Notice] Undefined index: default Is there a solution for this error?

Naktibalda commented 2 years ago

This is probably configuration error.

Please show the part of codeception.yaml or unit.suite.yaml containing Db configuration.

P.S. Unit tests are not supposed to use database.

Naktibalda commented 2 years ago

Stacktrace would be useful too.

FirasSahli2010 commented 2 years ago

I have the following

enabled:
    - Db:
        dns: 'mysql:host=localhost;dbname=test'
        user: 'user'
        password: ''
        dump: 'tests/_data/database/empty_db.sql'
        populate: true
        cleanup: true
        populator: 'mysql -u $user -h $host $dbname < $dump'
        skip_cleanup_if_failed: false,
        initial_queries:
          - 'CREATE DATABASE IF NOT EXISTS temp_db;'
          - 'USE temp_db;'
          - 'SET NAMES utf8;'

And during the test I do

 public function getConfig(): array
    {

        return [
            'dsn' => 'mysql:host=localhost;dbname=test',
            'user' => 'root',
            'password' => '',
            'dump' => 'tests/_data/database/empty_db.sql',
            'populate' => true,
            'cleanup' => true,
            'populator' => null,
            'skip_cleanup_if_failed' => false,

            'reconnect' => true,
            'initial_queries'=>  'CREATE DATABASE IF NOT EXISTS test;  USE test; SET NAMES utf8;'
        ];
    }

I got the error when I do

$this->module->haveInDatabase('logbook', array('fsahli', '2022-06-21 17:19:13', 'Test note asasas 2010', 'Something'));
Naktibalda commented 2 years ago

How is getConfig used?

I really need that stack trace, please run your test with -vvv parameter to get full stack trace.

FirasSahli2010 commented 2 years ago

Thanks a lot, I misconfigured the module