100 % 코드 커버리지를 얻으려고하지만 아래의 57 행을 어떻게 처리 할 지 결정할 수 없습니다. 그것은 단순히 결말이다}. 나는이 코드를 내 코드 전체에 걸쳐, else {와 같은 라인을 통해 가지고있다. 그러나 그것들은 다루지 않으며, 죽은 코드로 표시되지도 않는다.제공된 균열을 통과하는 코드 행을 덮기위한 테스트를 작성하는 방법
이 줄을 어떻게 커버 할 수 있습니까?
코드의 첫 번째 엿볼에서34 : public function addAction() {
35 :
36 2 : $form = new Roles_Form_Add();
37 :
38 2 : if ($this->getRequest()->isPost()) {
39 :
40 1 : if ($form->isValid($this->getRequest()->getPost())) {
41 :
42 1 : $clean = $form->getValues();
43 :
44 1 : $roleService = new Roles_Service_Role();
45 :
46 1 : $role = $roleService->fetchNew();
47 1 : $role->setFromArray($clean)
48 1 : ->save();
49 :
50 1 : $this->_helper->flashMessenger('A new role has been added.');
51 :
52 1 : $this->_helper->redirector('view','role','roles',array('id'=>$role->id));
53 1 : return;
54 :
55 : }
56 :
57 0 : }
58 :
59 1 : $form->setAction($this->_helper->url('add','role','roles'));
60 :
61 1 : $this->view->addRoleForm = $form;
62 :
63 1 : }
64 :
public function testAddAction() {
$this->dispatch('/roles/role/add');
$this->assertModule('roles');
$this->assertController('role');
$this->assertAction('add');
$this->assertQuery('form#addRole input#name');
}
public function testAddActionWithPost() {
$this->getRequest()->setMethod('POST')
->setPost('name','Test');
$this->dispatch('/roles/role/add');
$this->assertRedirectTo('/roles/role/view/id/1');
}
아마도 코드 커버리지 도구는 긍정적 인 조건을 테스트했지만 음수가 아닌 코드를 제안한 것 같습니다 (38 번 줄이 실행되지 않으면 블록이 실행될 때)? isPost()가 false를 리턴하는 테스트를 작성하십시오. –
게시물이없는 테스트가 있으며 사용 된 테스트를 추가했습니다. 다른 조언? – Sosy