I'm using JMSI18RoutingBundle on my project with this kind of config :
jms_i18n_routing: default_locale: "%locale%" locales: "%locales%" strategy: custom redirect_to_host: true hosts: en: "%urls_en%" de: "%urls_de%"
Everything is ok on prod, dev and test environment. But when i try to run phpunit with a simple webtestcase, the test fail coz this bundle cannot resolve the locale : here is where the code crash
JMS/I18nRoutingBundle/Router/I18nRouter.php line 222, methods matchI18n foreach ($availableHosts as $host) { if ($this->hostMap[$currentLocale] === $host) { $differentHost = false; break; } }
the $currentLocale is null so it crash.
on line 188 $request = $this->getRequest(); is also null
Here is my test :
`
namespace Tests\EuronewsBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class HomeControllerTest extends WebTestCase
{
/*
* Simple test to check we have a 200 OK + non empty body
/
public function testShowHome()
{
$client = static::createClient();
$client->followRedirects(true);
Because i'm running phpunit, php uses the CLI ISAPI, so i added this method in the AppKernel :
`
/*
* to enable Request with cli
/
protected function initializeContainer() {
parent::initializeContainer();
if (PHP_SAPI !== 'cli') return;
$request = new \Symfony\Component\HttpFoundation\Request();
$requestStack = new \Symfony\Component\HttpFoundation\RequestStack();
$requestStack->push($request);
$this->getContainer()->enterScope('request');
$this->getContainer()->set('request', $request, 'request');
$this->getContainer()->set('request_stack', $requestStack, 'request');
}/* */
`
But in fact it doesn't seem to help the bundle coz the request_stack in the container of the bundle is empty.
I'm using JMSI18RoutingBundle on my project with this kind of config :
jms_i18n_routing: default_locale: "%locale%" locales: "%locales%" strategy: custom redirect_to_host: true hosts: en: "%urls_en%" de: "%urls_de%"
Everything is ok on prod, dev and test environment. But when i try to run phpunit with a simple webtestcase, the test fail coz this bundle cannot resolve the locale : here is where the code crash
JMS/I18nRoutingBundle/Router/I18nRouter.php line 222, methods matchI18n foreach ($availableHosts as $host) { if ($this->hostMap[$currentLocale] === $host) { $differentHost = false; break; } }
the $currentLocale is null so it crash. on line 188 $request = $this->getRequest(); is also nullHere is my test :
` namespace Tests\EuronewsBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class HomeControllerTest extends WebTestCase { /* * Simple test to check we have a 200 OK + non empty body / public function testShowHome() { $client = static::createClient(); $client->followRedirects(true);
} `
Because i'm running phpunit, php uses the CLI ISAPI, so i added this method in the AppKernel : ` /* * to enable Request with cli / protected function initializeContainer() { parent::initializeContainer(); if (PHP_SAPI !== 'cli') return;
` But in fact it doesn't seem to help the bundle coz the request_stack in the container of the bundle is empty.