我有一个控制器,它以这种方式从会话数组中读取整数:
if ($session->has('administration'))
{
$id = $session->get('entity_id');
return $this->getDoctrine()->getRepository('AppBundle:SomeEntity')->find($id);
}
目前我正在为此控制器操作编写测试,但我找不到如何在会话数组中注入此整数。我尝试了以下方法:
$this->client = $this->makeClient(true);
$this->client->getContainer()->set('session.storage.options.entity_id', 12);
但是,这不起作用,似乎只是忽略了该值。因此,我的问题是如何在功能测试环境中将值存储在会话数组中?(注意:我使用的是 Liip 测试包(
可能产生影响的额外配置
// config_test.yml
liip_functional_test:
cache_sqlite_db: true
authentication:
username: "%test.username%"
password: "%test.password%"
framework:
test: ~
session:
storage_id: session.storage.mock_file
profiler:
collect: false
> Symfony 作为测试会话的模拟,如文档中此处所定义
use SymfonyComponentHttpFoundationSessionStorageMockFileSessionStorage;
use SymfonyComponentHttpFoundationSessionSession;
$session = new Session(new MockFileSessionStorage());
$session->set('entity_id', 12);