Symfony Codeception functional test: environment variable not found
Asked Answered
T

2

7

I'm using Codeception v2.4.1 with PHPUnit 7.1.3 in a new Symfony 4 project.

I created a functional test, and attempt to run it, and receive an error: ./vendor/bin/codecept run functional

There was 1 error:

---------
1) CustomerControllerCest: Customers on index
 Test  tests/functional/Controller/Internal/CustomerControllerCest.php:customersOnIndex

  [Symfony\Component\DependencyInjection\Exception\EnvNotFoundException] 
Environment variable not found: "CORS_ALLOW_ORIGIN".

I have a phpunit.xml file that has this environment configured:

 <php>
        <ini name="error_reporting" value="-1" />
        <env name="KERNEL_CLASS" value="App\Kernel" />
        <env name="APP_ENV" value="test" />
        <env name="APP_DEBUG" value="1" />
        <env name="APP_SECRET" value="191a5940854807ee081eaa57aff30562" />
        <env name="SHELL_VERBOSITY" value="-1" />
        <!-- define your env variables for the test env here -->
        <env name="CORS_ALLOW_ORIGIN" value="^https?://localhost:?[0-9]*$" />
    </php>

I also tried using .env.test, and included this same variable:

CORS_ALLOW_ORIGIN=^https?://localhost:?[0-9]*$

I checked in functional.suite.yml and my environment is set to test:

actor: FunctionalTester
modules:
    enabled:
        - Symfony:
            app_path: 'src'
            environment: 'test'
            em_service: ‘doctrine.orm.entity_manager’
#        - Doctrine2:
#            depends: Symfony
        # add a framework module here
        - \Helper\Functional

Not sure where the issue is. Is there an additional config where I tell codeception where to look for these environment variables?

Turd answered 4/5, 2018 at 21:47 Comment(0)
N
1

Use --bootstrap option, ex.

--bootstrap=config/bootstrap.php 

For Symfony 4

Nomination answered 23/3, 2020 at 18:14 Comment(0)
I
0

I used CORS_ALLOW_ORIGIN="*" php codecept run and it solved my problem.

Ixion answered 8/6, 2018 at 9:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.