我创建了一个 AuditLoggerBundle*,它有一个使用 Doctrine 事件(prePersist、preUpdate 和 preRemove)的服务,以便在 audit_log 表(AuditLog 实体)中创建一个新条目。
该捆绑包与我的其他捆绑包配合良好,但我想对其进行单元测试并对其进行功能测试。
问题是,为了对函数进行功能测试AuditLoggerListener,我需要至少有两个可以持久化、更新等的“假”实体。
在这个包中,我不知道如何做到这一点,因为我只有一个 AuditLog 实体,我需要使用两个实体(仅在测试中使用)。
这就是我看到持久功能测试的方式:
<?php
$animal = new Animal(); //this is a fake Auditable entity
$animal->setName('toto');
$em = new EntityManager(); //actually I will use the container to get this manager
$em->persist($animal);
$em->flush();
//Here we test that I have a new line in audit_log table with the right informations
Run Code Online (Sandbox Code Playgroud)
所以我的问题是我的包中没有任何 Animal 实体,我只需要这个来测试包,所以它必须只在测试数据库中创建,而不是在生产环境中创建(当我执行 app/console …