FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Wrong APP_ENV in Symfony Console command executed by RunBefore · Issue #6817 · Codeception/Codeception · GitHub

Repository navigation

Wrong APP_ENV in Symfony Console command executed by RunBefore #6817

Open

Description

What are you trying to achieve?

Run a Symfony Console command with the expected environment usign RunBefore extension.

What do you get instead?

The environment set in a Symfony Console command defined in the RunBefore extension config is not considered.

I set a command to run the migration before the suite.

extensions:
    enabled:
        - \Codeception\Extension\RunBefore:
    	        - bin/console --env=test doctrine:migrations:migrate --no-interaction

The env vars of Codeception command are forwarded to the commands added in the RunBefore configuration. As Codeception console is backed by Symfony Console, the same app variables are forwarded together. This action happens with the proc_open call on Symfony\Component\Process\Process::start method.

For that reason, the console already starts with $_ENV['APP_ENV'] == 'test'. Just for comparison, when the command is run directly, the value is null.

The value of $_ENV['APP_ENV'] is changed to dev in the Symfony\Component\Dotenv\Dotenv::populate method because APP_ENV is part of $_ENV['SYMFONY_DOTENV_VARS'] value. So the value defined in the .env file (dev by default) becomes the new value.

I am not considering setting env vars when on command. That is not supported by RunBefore extension currently.

Details

  • Codeception version: 5.1.2
  • PHP Version: 8.4.2
  • Operating System: Alpine
  • Installation type: Composer
  • List of installed packages (composer show)
behat/gherkin                            4.11.0  Gherkin DSL parser for PHP
clue/ndjson-react                        1.3.0   Streaming newline-delimited JSON (NDJSON) parser and encoder for ReactPHP.
codeception/codeception                  5.1.2   BDD-style testing framework
codeception/lib-asserts                  2.1.0   Assertion methods used by Codeception core and Asserts module
codeception/lib-innerbrowser             4.0.5   Parent library for all Codeception framework modules and PhpBrowser
codeception/lib-web                      1.0.6   Library containing files used by module-webdriver and lib-innerbrowser or module-phpbrowser
codeception/module-asserts               3.0.0   Codeception module containing various assertions
codeception/module-db                    3.1.4   DB module for Codeception
codeception/module-doctrine              3.1.0   Doctrine module for Codeception
codeception/module-phpbrowser            3.0.1   Codeception module for testing web application over HTTP
codeception/module-symfony               3.5.0   Codeception module for Symfony framework
codeception/module-webdriver             4.0.2   WebDriver module for Codeception
codeception/stub                         4.1.3   Flexible Stub wrapper for PHPUnit's Mock Builder
colinodell/json5                         3.0.0   UTF-8 compatible JSON5 parser for PHP
composer/pcre                            3.3.2   PCRE wrapping library that offers type-safe preg_* replacements.
composer/semver                          3.4.3   Semver library that offers utilities, version constraint parsing and validation.
composer/xdebug-handler                  3.0.5   Restarts a process without Xdebug.
cweagans/composer-patches                1.7.3   Provides a way to patch Composer packages.
doctrine/cache                           2.2.0   PHP Doctrine Cache library is a popular cache implementation that supports many different drivers such as red...
doctrine/collections                     2.2.2   PHP Doctrine Collections library that adds additional functionality on top of PHP arrays.
doctrine/dbal                            4.2.1   Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and manag...
doctrine/deprecations                    1.1.4   A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all depreca...
doctrine/doctrine-bundle                 2.13.1  Symfony DoctrineBundle
doctrine/doctrine-migrations-bundle      3.3.1   Symfony DoctrineMigrationsBundle
doctrine/event-manager                   2.0.1   The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine p...
doctrine/inflector                       2.0.10  PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/lowercas...
doctrine/instantiator                    2.0.0   A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer                           3.0.1   PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.
doctrine/migrations                      3.8.2   PHP Doctrine Migrations project offer additional functionality on top of the database abstraction layer (DBAL...
doctrine/orm                             3.3.1   Object-Relational-Mapper for PHP
doctrine/persistence                     3.4.0   The Doctrine Persistence project is a set of shared interfaces and functionality that the different Doctrine ...
doctrine/sql-formatter                   1.5.1   a PHP SQL highlighting library
egulias/email-validator                  4.0.3   A library for validating emails against several RFCs
evenement/evenement                      3.0.2   Événement is a very simple event dispatching library for PHP
fidry/cpu-core-counter                   1.2.0   Tiny utility to get the number of CPU cores.
fig/http-message-util                    1.1.5   Utility classes and constants for use with PSR-7 (psr/http-message)
friendsofphp/php-cs-fixer                3.65.0  A tool to automatically fix PHP code style
guzzlehttp/guzzle                        7.9.2   Guzzle is a PHP HTTP client library
guzzlehttp/promises                      2.0.4   Guzzle promises library
guzzlehttp/psr7                          2.7.0   PSR-7 message implementation that also provides common utility methods
infection/abstract-testframework-adapter 0.5.0   Abstract Test Framework Adapter for Infection
infection/codeception-adapter            0.4.3   Codeception Test Framework Adapter for Infection
infection/extension-installer            0.1.2   Infection Extension Installer
infection/include-interceptor            0.2.5   Stream Wrapper: Include Interceptor. Allows to replace included (autoloaded) file with another one.
infection/infection                      0.29.10 Infection is a Mutation Testing framework for PHP. The mutation adequacy score can be used to measure the eff...
infection/mutator                        0.4.0   Mutator interface to implement custom mutators (mutation operators) for Infection
justinrainbow/json-schema                5.3.0   A library to validate a json schema.
laminas/laminas-diactoros                3.5.0   PSR HTTP Message implementations
masterminds/html5                        2.9.0   An HTML5 parser and serializer.
mcustiel/phiremock-client                1.2.1   Client library to communicate with Phiremock server
mcustiel/phiremock-codeception-extension 3.1.0   Codeception extension for Phiremock. Allows to stub remote services for HTTP requests.
mcustiel/phiremock-codeception-module    2.0.0   Codeception module for PhireMock. Allows to stub remote services for HTTP requests.
mcustiel/phiremock-common                1.2.1   Common libraries for Phiremock
mcustiel/phiremock-server                1.5.1   A mocker for HTTP and REST services
monolog/monolog                          3.8.1   Sends your logs to files, sockets, inboxes, databases and various web services
myclabs/deep-copy                        1.12.1  Create deep copies (clones) of your objects
nikic/fast-route                         1.3.0   Fast request router for PHP
nikic/php-parser                         5.3.1   A PHP parser written in PHP
ondram/ci-detector                       4.2.0   Detect continuous integration environment and provide unified access to properties of current build
phar-io/manifest                         2.0.4   Component for reading phar.io manifest information from a PHP Archive (PHAR)
phar-io/version                          3.2.1   Library for handling version information and constraints
php-webdriver/webdriver                  1.15.2  A PHP client for Selenium WebDriver. Previously facebook/webdriver.
phpdocumentor/reflection-common          2.2.0   Common reflection classes used by phpdocumentor to reflect the code structure
phpdocumentor/reflection-docblock        5.6.1   With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve inform...
phpdocumentor/type-resolver              1.10.0  A PSR-5 based resolver of Class names, Types and Structural Element Names
phpstan/extension-installer              1.4.3   Composer plugin for automatic installation of PHPStan extensions
phpstan/phpdoc-parser                    2.0.0   PHPDoc parser with support for nullable, intersection and generic types
phpstan/phpstan                          2.0.4   PHPStan - PHP Static Analysis Tool
phpstan/phpstan-doctrine                 2.0.1   Doctrine extensions for PHPStan
phpstan/phpstan-symfony                  2.0.0   Symfony Framework extensions and rules for PHPStan
phpunit/php-code-coverage                11.0.8  Library that provides collection, processing, and rendering functionality for PHP code coverage information.
phpunit/php-file-iterator                5.1.0   FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-invoker                      5.0.1   Invoke callables with a timeout
phpunit/php-text-template                4.0.1   Simple template engine.
phpunit/php-timer                        7.0.1   Utility class for timing
phpunit/phpunit                          11.5.2  The PHP Unit Testing framework.
psr/cache                                3.0.0   Common interface for caching libraries
psr/clock                                1.0.0   Common interface for reading the clock.
psr/container                            2.0.2   Common Container Interface (PHP FIG PSR-11)
psr/event-dispatcher                     1.0.0   Standard interfaces for event handling.
psr/http-client                          1.0.3   Common interface for HTTP clients
psr/http-factory                         1.1.0   PSR-17: Common interfaces for PSR-7 HTTP message factories
psr/http-message                         1.1     Common interface for HTTP messages
psr/link                                 2.0.1   Common interfaces for HTTP links
psr/log                                  3.0.2   Common interface for logging libraries
psy/psysh                                0.12.7  An interactive shell for modern PHP.
ralouphie/getallheaders                  3.0.3   A polyfill for getallheaders.
react/cache                              1.2.0   Async, Promise-based cache interface for ReactPHP
react/child-process                      0.6.5   Event-driven library for executing child processes with ReactPHP.
react/dns                                1.13.0  Async DNS resolver for ReactPHP
react/event-loop                         1.5.0   ReactPHP's core reactor event loop that libraries can use for evented I/O.
react/http                               1.11.0  Event-driven, streaming HTTP client and server implementation for ReactPHP
react/promise                            3.2.0   A lightweight implementation of CommonJS Promises/A for PHP
react/socket                             1.16.0  Async, streaming plaintext TCP/IP and secure TLS socket server and client connections for ReactPHP
react/stream                             1.4.0   Event-driven readable and writable streams for non-blocking I/O in ReactPHP
rector/rector                            2.0.4   Instant Upgrade and Automated Refactoring of any PHP code
sanmai/later                             0.1.4   Later: deferred wrapper object
sanmai/pipeline                          6.12    General-purpose collections pipeline
sebastian/cli-parser                     3.0.2   Library for parsing CLI options
sebastian/code-unit                      3.0.2   Collection of value objects that represent the PHP code units
sebastian/code-unit-reverse-lookup       4.0.1   Looks up which function or method a line of code belongs to
sebastian/comparator                     6.2.1   Provides the functionality to compare PHP values for equality
sebastian/complexity                     4.0.1   Library for calculating the complexity of PHP code units
sebastian/diff                           6.0.2   Diff implementation
sebastian/environment                    7.2.0   Provides functionality to handle HHVM/PHP environments
sebastian/exporter                       6.3.0   Provides the functionality to export PHP variables for visualization
sebastian/global-state                   7.0.2   Snapshotting of global state
sebastian/lines-of-code                  3.0.1   Library for counting the lines of code in PHP source code
sebastian/object-enumerator              6.0.1   Traverses array structures and object graphs to enumerate all referenced objects
sebastian/object-reflector               4.0.1   Allows reflection of object attributes, including inherited and non-public ones
sebastian/recursion-context              6.0.2   Provides functionality to recursively process PHP variables
sebastian/type                           5.1.0   Collection of value objects that represent the types of the PHP type system
sebastian/version                        5.0.2   Library that helps with managing the version number of Git-hosted PHP projects
shish/safe                               2.6.4   PHP core functions that throw exceptions instead of returning FALSE on error (a less-abandoned fork of thecod...
staabm/side-effects-detector             1.0.5   A static analysis tool to detect side effects in PHP code
symfony/asset                            7.2.0   Manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and image files
symfony/asset-mapper                     7.2.0   Maps directories of assets & makes them available in a public directory with versioned filenames.
symfony/browser-kit                      7.2.0   Simulates the behavior of a web browser, allowing you to make requests, click on links and submit forms progr...
symfony/cache                            7.2.1   Provides extended PSR-6, PSR-16 (and tags) implementations
symfony/cache-contracts                  3.5.1   Generic abstractions related to caching
symfony/clock                            7.2.0   Decouples applications from the system clock
symfony/config                           7.2.0   Helps you find, load, combine, autofill and validate configuration values of any kind
symfony/console                          7.2.1   Eases the creation of beautiful and testable command line interfaces
symfony/css-selector                     7.2.0   Converts CSS selectors to XPath expressions
symfony/debug-bundle                     7.2.0   Provides a tight integration of the Symfony VarDumper component and the ServerLogCommand from MonologBridge i...
symfony/dependency-injection             7.2.0   Allows you to standardize and centralize the way objects are constructed in your application
symfony/deprecation-contracts            3.5.1   A generic function and convention to trigger deprecation notices
symfony/doctrine-bridge                  7.2.1   Provides integration for Doctrine with various Symfony components
symfony/doctrine-messenger               7.2.0   Symfony Doctrine Messenger Bridge
symfony/dom-crawler                      7.2.0   Eases DOM navigation for HTML and XML documents
symfony/dotenv                           7.2.0   Registers environment variables from a .env file
symfony/error-handler                    7.2.1   Provides tools to manage errors and ease debugging PHP code
symfony/event-dispatcher                 7.2.0   Provides tools that allow your application components to communicate with each other by dispatching events an...
symfony/event-dispatcher-contracts       3.5.1   Generic abstractions related to dispatching event
symfony/expression-language              7.2.0   Provides an engine that can compile and evaluate expressions
symfony/filesystem                       7.2.0   Provides basic utilities for the filesystem
symfony/finder                           7.2.0   Finds files and directories via an intuitive fluent interface
symfony/flex                             2.4.7   Composer plugin for Symfony
symfony/form                             7.2.0   Allows to easily create, process and reuse HTML forms
symfony/framework-bundle                 7.2.1   Provides a tight integration between Symfony components and the Symfony full-stack framework
symfony/http-client                      7.2.1   Provides powerful methods to fetch HTTP resources synchronously or asynchronously
symfony/http-client-contracts            3.5.2   Generic abstractions related to HTTP clients
symfony/http-foundation                  7.2.0   Defines an object-oriented layer for the HTTP specification
symfony/http-kernel                      7.2.1   Provides a structured process for converting a Request into a Response
symfony/intl                             7.2.0   Provides access to the localization data of the ICU library
symfony/mailer                           7.2.0   Helps sending emails
symfony/maker-bundle                     1.61.0  Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget ab...
symfony/messenger                        7.2.1   Helps applications send and receive messages to/from other applications or via message queues
symfony/mime                             7.2.1   Allows manipulating MIME messages
symfony/monolog-bridge                   7.2.0   Provides integration for Monolog with various Symfony components
symfony/monolog-bundle                   3.10.0  Symfony MonologBundle
symfony/notifier                         7.2.0   Sends notifications via one or more channels (email, SMS, ...)
symfony/options-resolver                 7.2.0   Provides an improved replacement for the array_replace PHP function
symfony/password-hasher                  7.2.0   Provides password hashing utilities
symfony/phpunit-bridge                   7.2.0   Provides utilities for PHPUnit, especially user deprecation notices management
symfony/polyfill-intl-grapheme           1.31.0  Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-icu                1.31.0  Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-intl-idn                1.31.0  Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-intl-normalizer         1.31.0  Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring                1.31.0  Symfony polyfill for the Mbstring extension
symfony/polyfill-php83                   1.31.0  Symfony polyfill backporting some PHP 8.3+ features to lower PHP versions
symfony/process                          7.2.0   Executes commands in sub-processes
symfony/property-access                  7.2.0   Provides functions to read and write from/to an object or array using a simple string notation
symfony/property-info                    7.2.1   Extracts information about PHP class' properties using metadata of popular sources
symfony/routing                          7.2.0   Maps an HTTP request to a set of configuration variables
symfony/runtime                          7.2.0   Enables decoupling PHP applications from global state
symfony/security-bundle                  7.2.0   Provides a tight integration of the Security component into the Symfony full-stack framework
symfony/security-core                    7.2.0   Symfony Security Component - Core Library
symfony/security-csrf                    7.2.0   Symfony Security Component - CSRF Library
symfony/security-http                    7.2.1   Symfony Security Component - HTTP Integration
symfony/serializer                       7.2.0   Handles serializing and deserializing data structures, including object graphs, into array structures or othe...
symfony/service-contracts                3.5.1   Generic abstractions related to writing services
symfony/stimulus-bundle                  2.22.1  Integration with your Symfony app & Stimulus!
symfony/stopwatch                        7.2.0   Provides a way to profile code
symfony/string                           7.2.0   Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a...
symfony/translation                      7.2.0   Provides tools to internationalize your application
symfony/translation-contracts            3.5.1   Generic abstractions related to translation
symfony/twig-bridge                      7.2.1   Provides integration for Twig with various Symfony components
symfony/twig-bundle                      7.2.0   Provides a tight integration of Twig into the Symfony full-stack framework
symfony/type-info                        7.2.1   Extracts PHP types information.
symfony/ux-turbo                         2.22.1  Hotwire Turbo integration for Symfony
symfony/validator                        7.2.0   Provides tools to validate values
symfony/var-dumper                       7.2.0   Provides mechanisms for walking through any arbitrary PHP variable
symfony/var-exporter                     7.2.0   Allows exporting any serializable PHP data structure to plain PHP code
symfony/web-link                         7.2.0   Manages links between resources
symfony/web-profiler-bundle              7.2.0   Provides a development tool that gives detailed information about the execution of any request
symfony/yaml                             7.2.0   Loads and dumps YAML files
theseer/tokenizer                        1.2.3   A small library for converting tokenized PHP source code into XML and potentially other formats
twig/extra-bundle                        3.18.0  A Symfony bundle for extra Twig extensions
twig/twig                                3.18.0  Twig, the flexible, fast, and secure template language for PHP
webmozart/assert                         1.11.0  Assertions to validate method input/output with nice error messages.
  • Suite configuration:
actor: FunctionalTester
extensions:
    enabled:
        - \Codeception\Extension\Phiremock:
            listen: 0.0.0.0:8086
            wait_until_ready: true
            wait_until_ready_timeout: 5
            expectations_path: tests/_expectations
        - \Codeception\Extension\RunBefore:
            - bin/console --env=test doctrine:migrations:migrate --no-interaction >> test

modules:
    enabled:
        - Asserts
        - Symfony:
            app_path: 'src'
            environment: 'test'
        - Doctrine:
            depends: Symfony
            cleanup: true
        - Phiremock:
            host: localhost
            port: 8086
            secure: false
            reset_before_each_test: true

coverage:
    enabled: true

Possible solution

The solution could be to remove the app environment variables to start the process with default system environment variables.

I can work in a PR if this makes sense for the project.

Activity

  1. xtix commented on Oct 17, 2025

    I faced the same issue. Setting SYMFONY_DOTENV_VARS variable in command SYMFONY_DOTENV_VARS="" bin/console --env=test doctrine:migrations:migrate --no-interaction makes it work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL