1
votes

I want to do a functional test with Symfony2 to check if a users profile is displayed and if a form is working:

namespace Dbe\DDBundle\Tests\Controller;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class ProfileControllerTest extends WebTestCase {

public function testNewsletterOnOff(){
    // Create a new client to browse the application
    $client = static::createClient();
    $client->request('GET', '/', array(), array(), array(
            'HTTP_ACCEPT_LANGUAGE'       => 'en',
    ));


    $crawler = $client->request('GET', '/en/profile/');

After executing the test in the console: phpunit -c app I get the following error message:

There was 1 error:

1) Dbe\DDBundle\Tests\Controller\ProfileControllerTest::testNewsletterOnOff
Undefined index: HTTP_ACCEPT_LANGUAGE

I guess this error comes up because a Controller is checking the browsers language. So how can I fake the HTTP_ACCEPT_LANGUAGE in functional tests with symfony? Thanks in advance for the help!

1

1 Answers

-1
votes

I found the solution, because the website visitor get's redirected depending on the browsers language i needed to define it before constructing the controller:

$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en';

$client = static::createClient();

$crawler = $client->request('GET', '/en/how');