これは、我々が今の進め方です:
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->クライアント - のような何かを試みることができます> getContainer() - > set( 'application.facebook_guzzle'、$ client); 'これはうまくいきません... – Matteo
@Matteoこれはパラメータでは機能しません(コンテナがコンパイルされているため) –