public function insert($set) { $adapter = $this->getAdapter(); $individualTable = new IndividualTable($adapter); $individualTable->insert(array(first_name => $set[individual_first_name], surname => $set[individual_surname], patronymic => $set[individual_patronymic])); $individual = $individualTable->getLastInsertRow(); $contractorTable = new ContractorTable($adapter); $contractor = $contractorTable->getRow($individual->contractor_id); $documentTable = new DocumentTable($adapter); $document = $documentTable->getRow($contractor->document_id); $document->notes = $set[document_notes]; $document->save(); return $document->document_id; }
/** * Method tests adding a duplicate title. */ public function testDuplicateTitle() { $oDocument = new Document(); $oDocument->setTitle('Foobar'); $oDocument->setInfo('Foobar, Foobar, Foobar'); $iID = $this->oDao->insert($oDocument); $this->assertNotNull($iID); $this->assertGreaterThan(1, $iID); $oPersistDoc = $this->oDao->find($iID); $this->assertInstanceOf('\\Application\\Model\\Document', $oPersistDoc); $oDocument2 = new Document(); $oDocument2->setTitle('Foobar'); $oDocument2->setInfo('Foobar, Foobar, Foobar'); try { $this->oDao->insert($oDocument2); } catch (InvalidQueryException $oEx) { $this->assertContains(' Duplicate entry', $oEx->getMessage()); } finally { //Clean up the db after testing $this->oDao->delete($oPersistDoc); } }