-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Description
I want to replace service container value with a test one to test if another implementation of the class injected by service container would work in my controller. I can set it via $client->getContainer()->set
method, but it does not work well. But after redirecting / following to another page container value is reset. I think code example will show the problem more detail:
$client = static::createClient();
// this one implements CarList interface
$carList = new CarList();
$carList->add($car1);
$carList->add($car2);
// ...
// now I replace default carlist implementation defined in the service
// container and used by CarController with my custom $carList.
$client->getContainer()->set('car.car_list', $carList);
// try to open CarController with the list of cars
$crawler = $this->requestGET($client, '/car/list/');
// and check if $car1 added to the custom CarList exists
$this->assertGreaterThan(0,
$crawler->filter('html:contains("'. $car1->getName() .'")')->count());
// well, it works fine! we replaced value defined in the container
// by our custom car list object
// now lets try to check it again!
$crawler = $this->requestGET($client, '/car/list/');
$this->assertGreaterThan(0,
$crawler->filter('html:contains("'. $car1->getName() .'")')->count());
// FAIL. container value has been reset (e.g. CarController works
// with its default carList implmenetation and there is no way
// to set a new container value, calling $client->getContainer()->set()
// does not work anymore
// the same result we have if we try to submit a new car via form,
// container value will not be set anymore and car will be added to
// the old carList implementation
Metadata
Metadata
Assignees
Labels
No labels