【发布时间】:2014-07-06 18:44:10
【问题描述】:
我正在为 Symfony2 创建一个小包,它只是提供服务;可以调用它在数据库中插入一行,包含几个参数:
class AuditLogService {
private $em;
public function __construct(EntityManager $em)
{
$this->em = $em;
}
public function log($type, $channel, $message) {
$log = new AuditLog();
$log->setType($type);
$log->setChannel($channel);
$log->setMessage($message);
$this->em->persist($log);
$this->em->flush();
}
}
现在我需要为它编写一个测试,所以基本上这里是我假设我应该采取的步骤:
编写一个获取记录器服务的测试,但改用模拟
entityManager?在使用模拟 em 的记录器上调用函数
尝试使用我在步骤 2 中使用的参数从模拟的 em 中取回它
判断我是否找到结果
我很确定理论上这些是正确的步骤,但是任何人都可以为我指出正确的方向吗?
我有这个:
public function testServiceLoaded()
{
$this->assertEquals(get_class($this->container->get('bbit_audit_log.service')), 'BBIT\AuditLogBundle\Services\AuditLogService');
}
这会返回以下错误:
“bbit_audit_log.service”依赖于不存在的服务“doctrine.orm.entity_manager”
我的容器似乎不包含entitymanager?
【问题讨论】:
标签: symfony