Local Module configuration in codeception tests


(Ingmar Vierhaus) #1

Hi there,

I’m working on an app based on the advanced application template.

I am using codeception and would like to use the Db module. It is configured in the suite configuration yaml file.

To keep the database configuration out of the repository, I am trying to put the password into a codeception param file, as described in "Modules And Helper: Dynamic Configuration With Params" in the codeception docs. However, codeception does not seem to read my parameters.

I have in tests/codeception/frontend/codeception.yml


params:

    - .env

The file tests/codeception/frontend/.env:


DB_USERNAME=homestead

DB_PASSWORD=secret

and in the suite configuration


        Db:

            dsn: 'mysql:host=localhost;dbname=testingdb'

            user: "%DB_USERNAME%"

            password: "DB_PASSWORD"

            dump: '../_data/base.sql'

            populate: true

            cleanup: false

            reconnect: true

The result is:


  Db: SQLSTATE[28000] [1045] Access denied for user '%DB_USERNAME%'@'localhost' (using password: YES) while creating PDO connection  

There is no error that the params file was not found or anything else that would help…

Any help with this would be very much appreciated!


(Ingmar Vierhaus) #2

Turns out my codeception version wasn’t up to date. Updated to 2.2.3 and now it works. Some points for anyone who tries the same with the advanced template:

  • Load the parameter file in the tests/codeception/frontend/codeception.yml or tests/codeception/backend/codeception.yml. Putting it in tests/codeception.yml did not work.

  • Then the given path needs to be relative to /frontend/ or /backend/ respectively.

My tests/codeception/config/params_local.yml:


parameters:

    DB_USERNAME: root

    DB_PASSWORD: password

In my tests/codeception/frontend/codeception.yml


params:

    - ../config/params_local.yml

In my tests/codeception/frontend/acceptance.suite.yml


    config:

        Db:

            dsn: 'mysql:host=localhost;dbname=testingdb'

            user: "%DB_USERNAME%"

            password: "%DB_PASSWORD%"

Hope this is helpful for someone.