私はSF2.8アプリに簡単な機能テストを実行しよう:実行SF2機能テスト:「スコープがアクティブである場合、コンテナをリセットすると、許可されていません」
- のPHPUnit 5.3.4
- コマンドライン:PHPUnitの-cアプリのsrc/LCH/MultisiteBundle /テスト/コントローラ/ SiteControllerTest
SiteControllerTest:
class SiteControllerTest extends WebTestCase
{
/**
* {@inheritDoc}
*/
protected function setUp()
{
$this->superadmin = static::createClient();
}
/*
* @group multisite
*/
public function testList()
{
// Nothing here yet.
}
protected function tearDown() {
parent::tearDown();
}
}
PHPUnitのリターン:
There was 1 error:
1) LCH\MultisiteBundle\Tests\Controller\SiteControllerTest::testList Symfony\Component\DependencyInjection\Exception\LogicException: Resetting the container is not allowed when a scope is active.
/var/www/html/sites/lch/loyalty/app/bootstrap.php.cache:2231 /var/www/html/sites/lch/loyalty/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php:182 /var/www/html/sites/lch/loyalty/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php:192 /var/www/html/sites/lch/loyalty/src/LCH/MultisiteBundle/Tests/Controller/SiteControllerTest.php:29
これはリセット時のコンテナクラス自体()メソッドによってthrowedさ:
/**
* {@inheritdoc}
*/
public function reset()
{
if (!empty($this->scopedServices)) {
throw new LogicException('Resetting the container is not allowed when a scope is active.');
}
$this->services = array();
}
しかし、私は、なぜ見つけることができません。これまでのサービス登録でスコープを使用していなかったので、デフォルトのself :: SCOPE_CONTAINERのいずれかにする必要があります。
ヒント?
ありがとうございます!
どこあなたは 'initializeContainer'方法を置くのですか? – con
AppKernelでは、Kernel :: initializeContainer()メソッドがオーバーライドされます。もちろん、 – nbonniot
はい。ありがとうございました :) – con