giorgiosironi / phpunit-selenium

Selenium RC integration for PHPUnit
http://www.phpunit.de/
Other
602 stars 271 forks source link

Selenium not using phpunit.xml env variables. #397

Closed Modelizer closed 4 years ago

Modelizer commented 7 years ago

When an actual browser is open; selenium uses default environment variable from .env file. But as specified in doc https://phpunit.de/manual/current/en/appendixes.configuration.html#appendixes.configuration.php-ini-constants-variables it should load it from phpunit.xml file. Actual issue was raised on https://github.com/Modelizer/Laravel-Selenium/issues/29

giorgiosironi commented 7 years ago

Which environment variables are we talking about? Generic variables or some that are used from PHPUnit_Selenium code?

Modelizer commented 7 years ago

Generic variables or some that are used from PHPUnit_Selenium code?

Global variables.

This would be a small example to understand

<php>
    <env name="APP_ENV" value="testing"/>
    <env name="CACHE_DRIVER" value="array"/>
    <env name="SESSION_DRIVER" value="array"/>
    <env name="QUEUE_DRIVER" value="sync"/>
    <env name="DB_CONNECTION" value="testing"/>
</php>
giorgiosironi commented 7 years ago

Can you provide the simplest test case that fails because of this behavior? These are env variables that should be set by PHPUnit more than by this project, but maybe there is some weird interaction.

Modelizer commented 7 years ago

Problem is when PHPUnit is run it gets env variables from phpunit.xml file which is correct but when selenium open a browser at that time it's not using phpunit.xml file.

Here you will find a sample test case. https://github.com/Modelizer/Laravel-Selenium/issues/29

In phpunit.xml file we are setting DB_CONNECTION as testing <env name="DB_CONNECTION" value="testing"/> But still when browser is loaded it reads from .env file. which is weird.

giorgiosironi commented 7 years ago

Do you mean the PHP code that runs inside the web server, when loaded from a browser run from PHPUnit_Selenium, does not see that environment variable? That's expected as PHPUnit does not run in the same PHP process as the code that creates the HTML page. Being able to set environment variables from outside the web server would be a huge security hole.

Modelizer commented 7 years ago

Being able to set environment variables from outside the web server would be a huge security hole.

I think we are not setting env variables outside the web server.

That's expected as PHPUnit does not run in the same PHP process as the code that creates the HTML page.

Yes. Selenium is not able to share the same instances which is been run from CLI.