Это, как мы переходим сейчас:
class TestKernel extends \AppKernel
{
public function __construct(\Closure $containerConfigurator, $environment = 'test', $debug = false)
{
$this->containerConfigurator = $containerConfigurator;
parent::__construct($environment, $debug);
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
parent::registerContainerConfiguration($loader);
$loader->load($this->containerConfigurator);
}
/**
* Override the parent method to force recompiling the container.
* For performance reasons the container is also not dumped to disk.
*/
protected function initializeContainer()
{
$this->container = $this->buildContainer();
$this->container->compile();
$this->container->set('kernel', $this);
}
}
Затем мы добавили этот метод в нашем базовом тестовом PHPUnit классе:
/**
* Rebuilds the container with custom container configuration.
*
* @param \Closure $containerConfigurator Closure that takes the ContainerBuilder and configures it.
*
* Example:
*
* $this->rebuildContainer(function (ContainerBuilder $container) {
* $container->setParameter('foo', 'bar');
* });
*/
public function rebuildContainer(\Closure $containerConfigurator) : ContainerInterface
{
if ($this->kernel) {
$this->kernel->shutdown();
$this->kernel = null;
$this->container = null;
}
$this->kernel = new TestKernel($containerConfigurator);
$this->kernel->boot();
$this->container = $this->kernel->getContainer();
return $this->container;
}
вы могли бы попробовать что-то вроде '$ this-> client- > getContainer() -> set ('application.facebook_guzzle', $ client); 'иногда это не работает ... – Matteo
@Matteo это не работает с параметрами (потому что контейнер скомпилирован) –