0
votes

I'm trying to write tests for my PHP backend with codeception. At one point I needed to test if there are changes made to the database.

I (tried) to follow the steps on the codeception tutorial but it wont work. I have installed the Db module via composer and added the config in my *.suite.yml and my codeception.yml, neither of them worked. Neither the AcceptanceTester class nor the FunctionalTester class contains any database related functions.

Every tutorial I found said "just use the functions", but without explaining how to get them/add them to the Tester. The tutorial on the codeception site just installs the module and without any explanation uses the functions, not even saying in which suite.

I also tried to create a Integration test, but couldn't find any source that describes how to do it properly. In my understanding (from the official page) I created a new integration.suite.yml file (see below) and created a test with it. But the tester still not recognizing any database functions.

codeception.yml:

extensions:
    enabled:
        - Codeception\Extension\RunFailed
        - Db:
                dsn: 'mysql:host=localhost;dbname=XXX'
                user: 'XXX'
                password: 'XXX'
                dump: 'tests/_data/dump.sql'
                populate: true
                cleanup: true
                populator: 'mysql -u $user -h $host $dbname < $dump'

integration.suite.yml

actor: UnitTester
modules:
  enabled:
    - Asserts
    - Db
    - \Helper\Unit

1

1 Answers

0
votes

Db module is not an extension, so it must be enabled in the modules section of suite configuration.

Db configuration can be provided as parameters of Db module or in modules: config: section either in suite configuration file or in codeception.yml.

modules:
  enabled:
    - Db:
        dsn: 'mysql:host=localhost;dbname=XXX'
        user: 'XXX'
        password: 'XXX'
        dump: 'tests/_data/dump.sql'
        populate: true
        cleanup: true
        populator: 'mysql -u $user -h $host $dbname < $dump'

Another important thing to consider is that you must set correct and distinct Actor name.
Your integration.suite.yaml contains actor: UnitTester, so it is very likely that UnitTester.php was overwritten by class generated for unit suite.