Closed krtorio closed 1 year ago
.env
is a default value of environment_file
setting so what you described is an expected behaviour.
https://github.com/Codeception/Codeception/blob/2.3.5/src/Codeception/Module/Laravel5.php#L122
If you look at my unit and functional suite configs you can see they are using .env.testing Does this mean all suites go back to using default if one suite uses .env?
Ok, it makes sense now. I will take a look at it, unless @DavertMik gets it first.
Laravel5 module is recreated for each suite. Class is instantiated and configs do not overlap. Could you add codecept_debug($this->config)
to trace the configuration changes?
Hi,
Where am I supposed to put this? In one of the tests? It gives me an undefined property error exception when I do that
[ErrorException] Undefined property: ProductListCest::$config
In Laravel5.php file
codecept_debug($this->config) shows nothing.
I used var_dump instead, showed that suite config uses .env.testing as indicated in the yml file. Also I could not recreate the issue, maybe because I upgraded to 2.3.5?
i got the same issue on fresh laravel 7.X.. it works properly until I add an environment_file
on unit.suite.yml
or codeception.yml
please see below
// unit.suite.yml
actor: UnitTester
modules:
enabled:
- Asserts
- \Helper\Unit
- Laravel5:
environment_file: .env.testing
//codeception.yml
paths:
tests: tests
output: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
actor_suffix: Tester
extensions:
enabled:
- Codeception\Extension\RunFailed
modules:
enabled:
- Laravel5
environment_file: .env.testing
I have the same problem with API tests. I have loaded .env.testing
into the suite, but the Laravel does not use it.
Api suite:
- REST: url: / depends: Laravel - Laravel: environment_file: .env.testing
Laravel version is 7.18 Codeception version is 4.2.2
I have found the problem source.
The Laravel creates an immutable environment repository instance \Dotenv\Repository\RepositoryInterface
. The instance is RepositoryBuilder
from the package vlucas/phpdotenv
.
When the Laravel tries change ENV-values to the .env
-file from the Codeception, the immutable RepositoryBuilder
does not.
The RepositoryBuilder
has removed since version 5.0.
My stack:
I have prepared the pull request - https://github.com/Codeception/module-laravel/pull/46
What are you trying to achieve?
run all tests after adding a new suite called 'api', forgot to point environment file to .env.testing (sqlite + test mongodb database) in the suite config api.suite.yml.
What do you get instead?
The unit and functional tests used local .env instead which uses my staging/demo mariadb and local mongodb database. Encountered errors due to trying to insert rows with duplicate ids. Mongodb local data wiped out because I use truncate in tearDown function. Mariadb data filled up with test seed data that I did not want to be put in the local database.
The unit and functional tests returned to using .env.testing settings only after removing all api suite files.
Details
composer show
) aws/aws-sdk-php 3.34.0 AWS SDK for PHP - Use Amazon... behat/gherkin v4.4.5 Gherkin DSL parser for PHP 5.3 codeception/codeception 2.3.5 BDD-style testing framework dnoegel/php-xdg-base-dir 0.1 implementation of xdg base d... doctrine/inflector v1.2.0 Common String Manipulations ... doctrine/instantiator 1.0.5 A small, lightweight utility... erusev/parsedown 1.6.3 Parser for Markdown. facebook/webdriver 1.4.1 A PHP client for Selenium We... fzaninotto/faker v1.7.1 Faker is a PHP library that ... guzzlehttp/guzzle 6.3.0 Guzzle is a PHP HTTP client ... guzzlehttp/promises v1.3.1 Guzzle promises library guzzlehttp/psr7 1.4.2 PSR-7 message implementation... hamcrest/hamcrest-php v1.2.2 This is the PHP port of Hamc... jakub-onderka/php-console-color 0.1 jakub-onderka/php-console-highlighter v0.3.2 jenssegers/mongodb v3.2.2 A MongoDB based Eloquent mod... laravel/framework v5.4.33 The Laravel Framework. laravel/tinker v1.0.2 Powerful REPL for the Larave... league/flysystem 1.0.41 Filesystem abstraction: Many... league/flysystem-aws-s3-v3 1.0.18 Flysystem adapter for the AW... mockery/mockery 0.9.9 Mockery is a simple yet flex... mongodb/mongodb 1.1.2 MongoDB driver library monolog/monolog 1.23.0 Sends your logs to files, so... mtdowling/cron-expression v1.2.0 CRON for PHP: Calculate the ... mtdowling/jmespath.php 2.4.0 Declaratively specify how to... myclabs/deep-copy 1.6.1 Create deep copies (clones) ... nesbot/carbon 1.22.1 A simple API extension for D... nikic/php-parser v3.1.0 A PHP parser written in PHP paragonie/randomcompat v2.0.10 PHP 5.x polyfill for random... phpdocumentor/reflection-common 1.0 Common reflection classes us... phpdocumentor/reflection-docblock 3.2.2 With this component, a libra... phpdocumentor/type-resolver 0.3.0 phpspec/prophecy v1.7.0 Highly opinionated mocking f... phpunit/php-code-coverage 4.0.8 Library that provides collec... phpunit/php-file-iterator 1.4.2 FilterIterator implementatio... phpunit/php-text-template 1.2.1 Simple template engine. phpunit/php-timer 1.0.9 Utility class for timing phpunit/php-token-stream 2.0.1 Wrapper around PHP's tokeniz... phpunit/phpunit 5.7.21 The PHP Unit Testing framework. phpunit/phpunit-mock-objects 3.4.4 Mock Object library for PHPUnit psr/http-message 1.0.1 Common interface for HTTP me... psr/log 1.0.2 Common interface for logging... psy/psysh v0.8.11 An interactive shell for mod... ramsey/uuid 3.7.0 Formerly rhumsaa/uuid. A PHP... sebastian/code-unit-reverse-lookup 1.0.1 Looks up which function or m... sebastian/comparator 1.2.4 Provides the functionality t... sebastian/diff 1.4.3 Diff implementation sebastian/environment 2.0.0 Provides functionality to ha... sebastian/exporter 2.0.0 Provides the functionality t... sebastian/global-state 1.1.1 Snapshotting of global state sebastian/object-enumerator 2.0.1 Traverses array structures a... sebastian/recursion-context 2.0.0 Provides functionality to re... sebastian/resource-operations 1.0.0 Provides a list of PHP built... sebastian/version 2.0.1 Library that helps with mana... stecman/symfony-console-completion 0.7.0 Automatic BASH completion fo... swiftmailer/swiftmailer v5.4.8 Swiftmailer, free feature-ri... symfony/browser-kit v3.3.6 Symfony BrowserKit Component symfony/console v3.3.6 Symfony Console Component symfony/css-selector v3.3.6 Symfony CssSelector Component symfony/debug v3.3.6 Symfony Debug Component symfony/dom-crawler v3.3.6 Symfony DomCrawler Component symfony/event-dispatcher v3.3.6 Symfony EventDispatcher Comp... symfony/finder v3.3.6 Symfony Finder Component symfony/http-foundation v3.3.6 Symfony HttpFoundation Compo... symfony/http-kernel v3.3.6 Symfony HttpKernel Component symfony/polyfill-mbstring v1.5.0 Symfony polyfill for the Mbs... symfony/process v3.3.6 Symfony Process Component symfony/routing v3.3.6 Symfony Routing Component symfony/translation v3.3.6 Symfony Translation Component symfony/var-dumper v3.3.6 Symfony mechanism for explor... symfony/yaml v3.3.6 Symfony Yaml Component tijsverkoyen/css-to-inline-styles 2.2.0 CssToInlineStyles is a class... vlucas/phpdotenv v2.4.0 Loads environment variables ... webmozart/assert 1.2.0 Assertions to validate metho...