0
votes

I got an Yii2 project which uses a database named frontend, but I would like to run my acceptance tests on a different database named codeception. The problem is when I run the tests it still uses the frontend database instead of the codeception one. Isn't it possible to run the acceptance tests on a different database or am I doing something wrong?

acceptance.suite.yml

class_name: AcceptanceTester
modules:
  enabled: [ WebDriver, Db ]

  config:
    Db:
        dsn: 'mysql:host=localhost;dbname=codeception'
        user: 'root'
        password: ''
        dump: _data/dump.sql
        populate: true
        cleanup: false
    WebDriver:
        url: 'http://localhost:8080/myproject/frontend/web'
        browser: 'firefox'

env:
  chrome:
        modules:
                config:
                        WebDriver:
                                  browser: 'chrome'

frontend\codeception.yml

namespace: tests\codeception\frontend
actor: Tester
paths:
  tests: .
  log: _output
  data: _data
  helpers: _support
settings:
  bootstrap: _bootstrap.php
  suite_class: \PHPUnit_Framework_TestSuite
  colors: true
  memory_limit: 1024M
  log: true
config:
  test_entry_url: http://localhost:8080/myproject/web/index-test.php
2

2 Answers

1
votes

Of course you can run acceptance tests against a test database!

However, you will have to configure the website to use the test database when running on a different url, and let Codeception run the tests against the test url. I did this with Yii1 and also with some custom frameworks.

I see you are already running codeception against index-test.php. In Yii1, there is a test.php config file where you can setup the connection for the test database, I assume Yii2 works in a similar way.

So look for the file in Yii2 where to configure the test database, and you are ready to go!

0
votes

If you are using PhpBrowser or WebDriver module, they make requests to website under test over HTTP and Codeception has no control over configuration and execution of the website.

Only functional tests (e.g. using a Yii2 module) can change configuration of the application.

configFile required - the path to the application config file. File should be configured for test environment and return configuration array.