panther icon indicating copy to clipboard operation
panther copied to clipboard

Use test environment when Panther running ?

Open bastien70 opened this issue 4 years ago • 7 comments

Hello, it looks like Panther does not launch with the test environment.

According to the doc ', we could put this in the .env.test file:

.env.test

PANTHER_APP_ENV=test

When I restart Panther, the environment is indicated as the test environment. However, if I go to my login page to log users with Panther, if I enter credentials belonging to the dev environment, it will work, but not if I enter information from the test environment. .

bastien70 avatar Jul 30 '20 15:07 bastien70

Same problem here.

The .env.test has a test-specific DATABASE_URL.

The test case retrieves an entityID from the database using the EntityManager. It then uses that ID in a route to retrieve the web page with $client->request('GET', sprintf('/object/edit/%s', $id)) and it gets a 404 NOT FOUND.

When the DATABASE_URL is removed from .env.test so that tests are run against the database in .env, then the above scenario works without any issues.

abzolv avatar Sep 10 '20 11:09 abzolv

I found a work-around for this problem.

In .env.test:

PANTHER_APP_ENV=panther

Then, in / create a new .env.panther and include the same DATABASE_URL that is in .env.test.

BTW, having PANTHER_APP_ENV=test in .env.test does not work because then you get:

Cannot set session ID after the session has started. (500 Internal Server Error)

abzolv avatar Sep 10 '20 12:09 abzolv

When you run phpunit - there is test environment in the test class, but when you call real browser from your test via $client->request() - there could be another environment, for example "dev" - if in your .env or .env.local file APP_ENV is set to dev.

You can set APP_ENV=test in your .env.local or create test.php front-controller based on index.php front-controller and set env inside test.php: $_SERVER['APP_ENV'] = 'test';

metaer avatar Jul 27 '21 15:07 metaer

Same problem here. I tried with PANTHER_APP_ENV=panther in my .ent.test Then I created a new .env.panther file with database_url but it's not working.

I launched panther y headless mode with PANTHER_NO_HEADLESS=1 PANTHER_DEVTOOLS=0 php bin/phpunit tests/UserTest.php

If I go to the profiler I can see that Panther uses dev environment and also that the database_url is the one from the dev file instead of the test db

Any help or clue how to fix this?

ikerib avatar May 09 '22 08:05 ikerib

@metaer describes the issue well. We can't really use a test.php, nor do we want to fiddle with .env.local every time we run tests. We're using the following solution for the same issue with php-webdriver:

  • Add APP_ENV=test to .env.test (distributed with repo, we also set APP_DEBUG=0)
  • From setUpBeforeClass, we call exec('cd /path/to/project/root/ && /path/to/php /path/to/composer dump-env test', $output, $resultCode);
  • From tearDownAfterClass, we call exec('rm /path/to/project/root/.env.local.php', $output, $resultCode);

Works great for us.

mattsbennett avatar Oct 18 '22 20:10 mattsbennett