We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Codeception Acceptance testing

For Acceptance RESTful API test I'm wondering how to properly set DB env configuration, that requests are not being made on real database, but temporarily Codeception db?

Change db adapter in your services container?

manually change config ENV in bootstrap? There isnt a codecption/phalcon way to autload different env?

Change db adapter in your services container?



58.4k

hey man

You can use module DB of Codeception, take look at https://github.com/phanbook/phanbook/blob/master/codeception.yml#L31

I'll be more specific,

  • there is a special .env.test file

test/_bootstrap.php

define('ENV', '.env.test');

codeception.yml

modules:
    config:
        Db:
            dsn: 'mysql:host=localhost;dbname=test'
            user: 'test'
            password: 'test'
            dump: tests/_data/dump.sql

api.suite.yml

class_name: ApiTester
modules:
    enabled:
        - \Helper\Api
        - \Helper\JsonSchema
        - Db:
            cleanup: true
        - REST:
            depends: PhpBrowser
            url: https://localhost:8888
            part: Json
  • inside loader

defined('ENV') or define('ENV', '.env');

$dotenv = new \Dotenv\Dotenv(__DIR__.'/../', ENV);
$dotenv->load();

So, when request is created via PhpBrowser module, it doesn't use a '.env.test' but '.env' like a regular request to API, should I use Phalcon2 module for REST, or there is some better way to load a test database?