简体   繁体   中英

Symfony2: running automated tests in a custom environment

I'm trying to run Symfony 2 PHP unit tests for a REST API in a custom environment, other than the default 'test' environment.

The purpose is to be able to do a quick sanity check after deploying the rest API, in any environment (eg int, prod)

I managed to pass the environment to the WebTestCase class, when creating a new kernel/client. My problem is that I'm now getting the following error:

"The session id is too long or contains illegal characters, valid characters are az, AZ, 0-9"

I can fix that by changing the session storage to filesystem in the config.[targetenvironment].yml, but I don't want to use filesystem storage when in prod for instance.

framework:
    test: ~
    session:
        storage_id: session.storage.filesystem

Is there any way around this issue?

Thanks

In chapter 11 of the PHPUnit manual there is a section on mocking the filesystem . This basically intercepts all filesystem calls, so making sure the test you run has no side-effects. This should solve your problem if you're calling functions directly (ie if the php instance running PHPUnit is also the one running your code).

If, however, your calls are going through the web server then PHPUnit configuration cannot control the remote environment. In that case you could try a special Apache configuration that sets an environmental variable based on the clients IP address and/or user-agent string and then in your code use that environmental variable to override the default session storage, or anything else you need to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM