3
votes

I have a project in Symfony4 with doctrine DB, everything flies.

I would like to add some functional and unit testing with Codeception. I followed the docs and added this to my functional.suite.yml:

actor: FunctionalTester
modules:
    enabled:
        - Symfony:
            app_path: 'src'
            environment: 'test'
        - Doctrine2:
            depends: Symfony
#            cleanup: true
        - \Helper\Functional
#       - Db
    step_decorators: ~        

However, when running vendor/bin/codecept run I get an ugly:

In EnvVarProcessor.php line 131:

Environment variable not found: "DATABASE_URL".

I can't see anything else related in the docs, so not sure what I'm missing.

2
I wonder what bin/console about --env=test shows in comparison to --env=dev - Jakumi

2 Answers

2
votes

I can't unfortunately explain the mechanisms behind it, but to resolve it I had to add DATABASE_URL environment variable to my OS.

export DATABASE_URL='mysql: ...';

This seemed very weird solution to me (which, again, I have no idea why Codeception would require this), so I kept digging. Something I discovered later, but seems actually cause the whole situation is how I installed Codeception. If you go to codeception docs you can read:

If you don't plan to do acceptance testing, you can get minimal installation of Codeception by requiring codeception/base

EDIT July 2020: Information about minimal install was removed from the linked website, looks like Codeception doesn't provide that option anymore.

This was how I had it installed. After playing around a lot I pulled a version of my code before codeception and installed using composer require codeception/codeception --dev (so the full version). After installing this way I had no issues.

1
votes

Does your codeception.yml configuration file have this section:

params:
- .env
- .env.test
- ...

If it has, you need to check the last .env file on the list and make sure that it has the DATABASE_URL variable set.

The other solution is that you remove every file from the list except the .env your app is using. (I don't suggest it)

When each file from this list loads, it overrides the variables that are present in the previous file.