andyw4's avatar

Setting environment variable inside test?

Can anyone give me a pointer on how I go about setting an environment variable inside a test function?

I have a middleware in my app that checks for an environment variable - if this variable is true, it redirects to a 'closed' page.

How can I set this variable for a single test so I can check that the middleware works?

0 likes
6 replies
dmcglone's avatar

You should be able to pass your middleware as an argument

andyw4's avatar

Sorry, I'm not making myself clear - I've written the middleware, it works fine.

I'm trying to work out how to test it using phpunit - so a function along the lines of

public function testClosedMiddleware()
{
    setenv('APP_CLOSED',true);

    $this->visit('/')
        ->seePageIs('/closed');
}

But how do I set the environment variable in the test?

dmcglone's avatar

I'm not sure how you would go about testing it with PHPUnit. :-(

Please or to participate in this conversation.