我使用功能测试进行某些控制器操作。 Controller渲染使用Service with Dependency Injection的twig模板。
但是当我执行测试时,我收到一个错误:Resetting the container is not allowed when a scope is active.
出了什么问题?
services:
ad_backend.menu:
class: AdBackendBundle\Services\MenuService
arguments: [@doctrine.orm.entity_manager, @request_stack, @router, @twig]
Twig config:
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
globals:
service_menu: "@ad_backend.menu"
在树枝上:
{{ service_menu.renderMenu({name: 'menu', visible: true})|raw }}
测试代码:
public function testMenus()
{
$client = static::createClient();
$crawler = $client->request('GET', '/backend/menu/list');
$this->assertEquals(200, $client->getResponse()->getStatusCode());
$this->assertGreaterThanOrEqual(0, $crawler->filter('.block-menu-list')->count());
}
完整错误输出:
Resetting the container is not allowed when a scope is active.
/home/voodoo/Dev/server/ad/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:360
/home/voodoo/Dev/server/ad/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php:182
/home/voodoo/Dev/server/ad/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php:192
Resetting the container is not allowed when a scope is active.
/home/voodoo/Dev/server/ad/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:360
/home/voodoo/Dev/server/ad/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php:182
/home/voodoo/Dev/server/ad/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php:192