public function testGetFileLicenseMatches() { $this->testDb->createPlainTables(array('license_ref', 'uploadtree', 'license_file', 'agent')); $this->testDb->insertData_license_ref(); $lic0 = $this->dbManager->getSingleRow("Select * from license_ref limit 1"); $licenseRefNumber = $lic0['rf_pk']; $licenseFileId = 1; $pfileId = 42; $agentId = 23; $matchPercent = 50; $uploadtreeId = 512; $uploadID = 123; $left = 2009; $right = 2014; $agentName = "fake"; $agentRev = 1; $mydate = "'2014-06-04 14:01:30.551093+02'"; $this->testDb->createViews(array('license_file_ref')); $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk, rf_fk, agent_fk, rf_match_pct, rf_timestamp, pfile_fk)\n VALUES ({$licenseFileId}, {$licenseRefNumber}, {$agentId}, {$matchPercent}, {$mydate}, {$pfileId})"); $this->dbManager->queryOnce("INSERT INTO uploadtree (uploadtree_pk, upload_fk, pfile_fk, lft, rgt)\n VALUES ({$uploadtreeId}, {$uploadID}, {$pfileId}, {$left}, {$right})"); $stmt = __METHOD__ . '.insert.agent'; $this->dbManager->prepare($stmt, "INSERT INTO agent (agent_pk, agent_name, agent_rev, agent_enabled) VALUES (\$1,\$2,\$3,\$4)"); $this->dbManager->execute($stmt, array($agentId, $agentName, $agentRev, 'true')); $licDao = new LicenseDao($this->dbManager); $itemTreeBounds = new ItemTreeBounds($uploadtreeId, "uploadtree", $uploadID, $left, $right); $matches = $licDao->getAgentFileLicenseMatches($itemTreeBounds); $licenseRef = new LicenseRef($licenseRefNumber, $lic0['rf_shortname'], $lic0['rf_fullname']); $agentRef = new AgentRef($agentId, $agentName, $agentRev); $expected = array(new LicenseMatch($pfileId, $licenseRef, $agentRef, $licenseFileId, $matchPercent)); assertThat($matches, equalTo($expected)); assertThat($matches[0], is(anInstanceOf(LicenseMatch::classname()))); $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount() - $this->assertCountBefore); }
/** * @return M\MockInterface */ protected function createLicenseMatchWithLicId($licId) { $licenseMatch = M::mock(LicenseMatch::classname()); $licenseMatch->shouldReceive("getLicenseId")->withNoArgs()->andReturn($licId); return $licenseMatch; }
/** * @return M\MockInterface */ protected function createLicenseMatch($licenseId, $licenseShortName, $agentId, $agentName, $matchId, $percentage) { $licenseRef = M::mock(LicenseRef::classname()); $licenseRef->shouldReceive("getId")->withNoArgs()->andReturn($licenseId); $licenseRef->shouldReceive("getShortName")->withNoArgs()->andReturn($licenseShortName); $agentRef = M::mock(LicenseRef::classname()); $agentRef->shouldReceive("getAgentId")->withNoArgs()->andReturn($agentId); $agentRef->shouldReceive("getAgentName")->withNoArgs()->andReturn($agentName); $agentRef->shouldReceive("getAgentName")->withNoArgs()->andReturn($agentName); $licenseMatch = M::mock(LicenseMatch::classname()); $licenseMatch->shouldReceive("getLicenseRef")->withNoArgs()->andReturn($licenseRef); $licenseMatch->shouldReceive("getAgentRef")->withNoArgs()->andReturn($agentRef); $licenseMatch->shouldReceive("getLicenseFileId")->withNoArgs()->andReturn($matchId); $licenseMatch->shouldReceive("getPercentage")->withNoArgs()->andReturn($percentage); return array($licenseMatch, $licenseRef, $agentRef); }