public function testGetArrayCopyReturnsAnArrayWithPropertyValues() { $issue = new Issue(); $data = array('id' => 123, 'title' => 'some title'); $issue->exchangeArray($data); $copyArray = $issue->getArrayCopy(); $this->assertSame($data['id'], $copyArray['id'], '"id" was not set correctly'); $this->assertSame($data['title'], $copyArray['title'], '"title" was not set correctly'); }
public function testSaveIssueWillUpdateExistingIssuesIfTheyAlreadyHaveAnId() { $issueData = array('id' => 123, 'title' => 'Gun Control'); $issue = new Issue(); $issue->exchangeArray($issueData); $resultSet = new ResultSet(); $resultSet->setArrayObjectPrototype(new Issue()); $resultSet->initialize(array($issue)); $mockTableGateway = $this->getMock('Zend\\Db\\TableGateway\\TableGateway', array('select', 'update'), array(), '', false); $mockTableGateway->expects($this->once())->method('select')->with(array('id' => 123))->will($this->returnValue($resultSet)); $mockTableGateway->expects($this->once())->method('update')->with(array('title' => 'Gun Control', 'user_id' => 1), array('id' => 123)); $issueTable = new IssueTable($mockTableGateway); $issueTable->saveIssue($issue, 1); }
public function addAction() { if (!$this->zfcUserAuthentication()->hasIdentity()) { return $this->redirect()->toRoute('issue'); } $form = new IssueForm(); $form->get('submit')->setValue('Add'); $request = $this->getRequest(); if ($request->isPost()) { $issue = new Issue(); $form->setInputFilter($issue->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $issue->exchangeArray($form->getData()); $this->getIssueTable()->saveIssue($issue, $this->zfcUserAuthentication()->getIdentity()->getId()); // Redirect to list of issues return $this->redirect()->toRoute('issue'); } } return array('form' => $form); }