Reputation: 8109
I have a Symfony 2 application, which uses a REST interace. I want to execute integrations tests with different environments. The tests should be executed:
How can I specify, which test environment is executed? Currently I start tests using
phpunit -c app/
from within the application folder. However I dont want to duplicate the app folder.
Update
Specifically I have a REST service, which is responsible for doint REST calls, let's call it RestBase
. At some point it builds up a URL like: $urlPrefix.$restPath
. $urlPrefix
is different for dev
, stage
, prod
environments. Currently this configuration is done in config_*.yml
. However I want to run tests against different urlPrefix
. Conceptually I want to have something like:
phpunit -c app/ **-env=test**
where urlPrefix
is http://localhost:8888
and
phpunit -c app/ **-env=test2**
runs against another another environment, with a different setting for urlPrefix
.
Summarized question
How to execute tests in another environment than test
, e.g. test2
(and not change this programmatically)?
Upvotes: 1
Views: 3330
Reputation: 8109
I ended up writing a custom bootstrap.php
as it is described here: http://php-and-symfony.matthiasnoback.nl/2011/10/symfony2-use-a-bootstrap-file-for-your-phpunit-tests-and-run-some-console-commands/
I then start the configuration using:
phpunit -c app/mockup.phpunit.php
To run tests against the real interface using:
phpunit -c app/
Upvotes: 1
Reputation: 8915
So you are functional testing you REST api using phpunit.
Symfony2 already provides a way to bypass front controllers by directy calling your http Kernel.
All you have to do is to extend the WebTestCase class (inheriting itself from Phpunit Test_Case):
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class MyControllerTest extends WebTestCase
{
public function testGET()
{
// Create a new client to browse the application
$client = static::createClient();
$crawler = $client->request('GET', '/api/v1/test');
$this->assertTrue(200 === $client->getResponse()->getStatusCode());
}
}
Upvotes: 1