jeudi 24 septembre 2015

Symfony Tests and enviroment

I have the following problem:

I have a route defined only for development or testing purposes, which I 'protect' by doing the following in my controller:

public function testAction()
{

    $env = $this->container->get('kernel')->getEnvironment();

    if ($env !== 'test' || $env !== 'dev')
    {
        throw $this->createNotFoundException('Oops, page not available in production environment...');
    }

    ...
}

Now this works well in production, but when I try to run my tests it keeps firing an 404.

When I echo the $env variable during tests it says: test

FtestFtestFtest.......... (output from phpunit)

I've tryed using != and " but no luck.

In the tests I do something alike:

$client = static::createClient();
$client->request('GET', '/basecontroller/test');
$this->assertEquals(200, $client->getResponse()->getStatusCode());

When I comment out the $env check all tests pass. What could be the cause of this ?

Thanks in advance

Aucun commentaire:

Enregistrer un commentaire