我目前正在使用 Symfony2 并使用 PHPUnit 测试我的项目。我想测试提交表单时参数错误或 URL 不完整时的异常。
我浏览了 Symfony2 和 PHPUnit 的文档,但没有找到任何类/方法来执行此操作。
如何更改表单操作的值?我想使用 PHPUnit,以便创建的报告是最新的,并且我可以看到我的代码的覆盖范围。
编辑:
为了澄清我的问题,一些新内容。如何在控制器中测试以“>”开头的行?( throw $this->createNotFoundException('Unable to find ParkingZone entity.');)
当用户修改操作链接时,在控制器中,该过程将经历异常(或错误消息,如果选择此操作)。我该如何测试这个案例?
控制器
/**
* Edits an existing ParkingZone entity.
*
* @Route("/{id}/update", name="parkingzone_update")
* @Method("post")
* @Template("RatpGarageL1Bundle:ParkingZone:edit.html.twig")
*/
public function updateAction($id)
{
$em = $this->getDoctrine()->getEntityManager();
$entity = $em->getRepository('RatpGarageL1Bundle:ParkingZone')->find($id);
if (!$entity) {
> throw $this->createNotFoundException('Unable to find ParkingZone entity.');
}
$editForm = $this->createForm(new ParkingZoneType(), $entity);
$deleteForm = $this->createDeleteForm($id);
$request = $this->getRequest();
$editForm->bindRequest($request);
if ($editForm->isValid()) {
$em->persist($entity);
$em->flush();
return …Run Code Online (Sandbox Code Playgroud)