Skip to content

Conversation

barmax
Copy link

@barmax barmax commented Nov 4, 2022

Fixed #20

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.

@barmax barmax changed the title Edited the way of loading the environment Use the testing environment file specified in a suite Nov 4, 2022
@barmax barmax requested a review from Naktibalda November 7, 2022 09:00
@barmax
Copy link
Author

barmax commented Nov 7, 2022

May I ask you when the PR will merge to the main-branch?

The PR helps with my project.

@Naktibalda
Copy link
Member

I don't understand if this change realy fixes the linked issue, but it shouldn't do any harm, so I'm merging it.
Also noone else wanted to review it.

@Naktibalda Naktibalda merged commit 9956560 into Codeception:main Nov 19, 2022
@barmax
Copy link
Author

barmax commented Nov 22, 2022

I don't understand if this change realy fixes the linked issue

Ok. I explain what will change. I have followed a stack by the xDebug.

When we want use a test database in tests (my case is api tests) we should replace credentials that Laravel uses.
Tests for Laravel start with creating the Laravel application. The application loads with data from configs that get values from the .env-file and set them in the $_ENV variable.
After that we load a test env-file and we expect that the app will use values from the test .env-file.
However, when the app tries to rewrite existing values in the $_ENV an immutable writer does not it.
And when we call an endpoint, the app uses the $_ENV-values from the the original .env-file and we don't get data from the test database from a test suite.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

failed to use testing environment file specified in suite config

2 participants