36 private $itemTreeBounds;
38 private $agentLicenseEventProcessor;
39 private $dbManagerMock;
40 private $latestScanners = array(array(
'agent_pk'=>23,
'agent_name'=>
'nomos'),
41 array(
'agent_pk'=>22,
'agent_name'=>
'monk'));
43 protected function setUp()
45 $this->licenseDao = M::mock(LicenseDao::class);
46 $this->agentsDao = M::mock(AgentDao::class);
48 $this->itemTreeBounds = M::mock(ItemTreeBounds::class);
53 $this->dbManagerMock = M::mock(DbManager::class);
54 $this->dbManagerMock->shouldReceive(
'prepare');
55 $this->dbManagerMock->shouldReceive(
'execute');
56 $this->dbManagerMock->shouldReceive(
'fetchArray')
57 ->andReturn($this->latestScanners[0],$this->latestScanners[1],
false);
58 $this->dbManagerMock->shouldReceive(
'freeResult');
59 $container = M::mock(
'ContainerBuilder');
60 $container->shouldReceive(
'get')->withArgs(array(
'db.manager'))->andReturn($this->dbManagerMock);
63 protected function tearDown()
74 $nomos = $this->latestScanners[0];
75 $monk = $this->latestScanners[1];
76 list($licenseMatch1, $licenseRef1, $agentRef1) = $this->
createLicenseMatch(5,
"licA", $nomos[
'agent_pk'], $nomos[
'agent_name'], 453, null);
77 list($licenseMatch2, $licenseRef2, $agentRef2) = $this->
createLicenseMatch(5,
"licA", $monk[
'agent_pk'], $monk[
'agent_name'], 665, 95);
78 list($licenseMatch3, $licenseRef3, $agentRef3) = $this->
createLicenseMatch(7,
"licB", $monk[
'agent_pk'], $monk[
'agent_name'], 545, 97);
79 $licenseMatches = array($licenseMatch1, $licenseMatch2, $licenseMatch3);
81 $this->itemTreeBounds->shouldReceive(
'getUploadId')->withNoArgs()->andReturn($uploadId);
82 $this->licenseDao->shouldReceive(
'getAgentFileLicenseMatches')->once()
83 ->withArgs(array($this->itemTreeBounds,LicenseMap::TRIVIAL))
84 ->andReturn($licenseMatches);
85 $scannerDetectedLicenses = $this->agentLicenseEventProcessor->getScannerDetectedLicenses($this->itemTreeBounds);
87 assertThat($scannerDetectedLicenses, is(array(
93 public function testGetScannerDetectedLicenseDetails()
97 $nomos = $this->latestScanners[0];
98 $monk = $this->latestScanners[1];
99 list($licenseMatch1, $licenseRef1, $agentRef1) = $this->
createLicenseMatch($licId,
"licA", $nomos[
'agent_pk'], $nomos[
'agent_name'], 453, null);
100 list($licenseMatch2, $licenseRef2, $agentRef2) = $this->
createLicenseMatch($licId,
"licA", $monk[
'agent_pk'], $monk[
'agent_name'], 665, 95);
101 $licenseMatches = array($licenseMatch1, $licenseMatch2);
103 $this->itemTreeBounds->shouldReceive(
'getUploadId')->withNoArgs()->andReturn($uploadId);
104 $this->licenseDao->shouldReceive(
'getAgentFileLicenseMatches')->once()
105 ->withArgs(array($this->itemTreeBounds,LicenseMap::TRIVIAL))
106 ->andReturn($licenseMatches);
109 $reflection = new \ReflectionClass($this->agentLicenseEventProcessor);
110 $method = $reflection->getMethod(
'getScannerDetectedLicenseDetails');
111 $method->setAccessible(
true);
112 $latestAgentDetectedLicenses = $method->invoke($this->agentLicenseEventProcessor,$this->itemTreeBounds);
114 assertThat($latestAgentDetectedLicenses, array(
116 array(
'id' => $licId,
'licenseRef' => $licenseRef1,
'agentRef' => $agentRef1,
'matchId' => 453,
'percentage' => null)
119 array(
'id' => $licId,
'licenseRef' => $licenseRef2,
'agentRef' => $agentRef2,
'matchId' => 665,
'percentage' => 95)
124 public function testGetScannerDetectedLicenseDetailsWithUnknownAgent()
127 list($licenseMatch1, $licenseRef1, $agentRef1) = $this->
createLicenseMatch(5,
"licA", 23,
"nomos", 453, null);
128 list($licenseMatch2, $licenseRef2, $agentRef2) = $this->
createLicenseMatch(5,
"licA", 22,
"unknown", 665, 95);
129 $licenseMatches = array($licenseMatch1, $licenseMatch2);
131 $this->itemTreeBounds->shouldReceive(
'getUploadId')->withNoArgs()->andReturn($uploadId);
132 $this->licenseDao->shouldReceive(
'getAgentFileLicenseMatches')->once()
133 ->withArgs(array($this->itemTreeBounds,LicenseMap::TRIVIAL))
134 ->andReturn($licenseMatches);
137 $reflection = new \ReflectionClass($this->agentLicenseEventProcessor);
138 $method = $reflection->getMethod(
'getScannerDetectedLicenseDetails');
139 $method->setAccessible(
true);
140 $latestAgentDetectedLicenses = $method->invoke($this->agentLicenseEventProcessor,$this->itemTreeBounds);
142 assertThat($latestAgentDetectedLicenses, is(array(
145 array(
'id' => 5,
'licenseRef' => $licenseRef1,
'agentRef' => $agentRef1,
'matchId' => 453,
'percentage' => null)
151 public function testGetScannerDetectedLicenseDetailsWithOutdatedMatches()
154 list($licenseMatch1, $licenseRef1, $agentRef1) = $this->
createLicenseMatch(5,
"licA", 17,
"nomos", 453, null);
155 list($licenseMatch2, $licenseRef2, $agentRef2) = $this->
createLicenseMatch(5,
"licA", 18,
"monk", 665, 95);
156 $licenseMatches = array($licenseMatch1, $licenseMatch2);
158 $this->itemTreeBounds->shouldReceive(
'getUploadId')->withNoArgs()->andReturn($uploadId);
159 $this->licenseDao->shouldReceive(
'getAgentFileLicenseMatches')->once()
160 ->withArgs(array($this->itemTreeBounds,LicenseMap::TRIVIAL))
161 ->andReturn($licenseMatches);
164 $reflection = new \ReflectionClass($this->agentLicenseEventProcessor);
165 $method = $reflection->getMethod(
'getScannerDetectedLicenseDetails');
166 $method->setAccessible(
true);
167 $latestAgentDetectedLicenses = $method->invoke($this->agentLicenseEventProcessor,$this->itemTreeBounds);
169 assertThat($latestAgentDetectedLicenses, is(array()));
172 public function testGetScannerDetectedLicenseDetailsNoLicenseFoundShouldBeSkipped()
175 list($licenseMatch1, $licenseRef1, $agentRef1) = $this->
createLicenseMatch(5,
"No_license_found", 23,
"nomos", 453, null);
176 $licenseMatches = array($licenseMatch1);
178 $this->itemTreeBounds->shouldReceive(
'getUploadId')->withNoArgs()->andReturn($uploadId);
179 $this->licenseDao->shouldReceive(
'getAgentFileLicenseMatches')->once()
180 ->withArgs(array($this->itemTreeBounds,LicenseMap::TRIVIAL))
181 ->andReturn($licenseMatches);
184 $reflection = new \ReflectionClass($this->agentLicenseEventProcessor);
185 $method = $reflection->getMethod(
'getScannerDetectedLicenseDetails');
186 $method->setAccessible(
true);
187 $latestAgentDetectedLicenses = $method->invoke($this->agentLicenseEventProcessor,$this->itemTreeBounds);
189 assertThat($latestAgentDetectedLicenses, is(array()));
195 protected function createLicenseMatch($licenseId, $licenseShortName, $agentId, $agentName, $matchId, $percentage)
197 $licenseRef = M::mock(LicenseRef::class);
198 $licenseRef->shouldReceive(
"getId")->withNoArgs()->andReturn($licenseId);
199 $licenseRef->shouldReceive(
"getShortName")->withNoArgs()->andReturn($licenseShortName);
201 $agentRef = M::mock(LicenseRef::class);
202 $agentRef->shouldReceive(
"getAgentId")->withNoArgs()->andReturn($agentId);
203 $agentRef->shouldReceive(
"getAgentName")->withNoArgs()->andReturn($agentName);
204 $agentRef->shouldReceive(
"getAgentName")->withNoArgs()->andReturn($agentName);
206 $licenseMatch = M::mock(LicenseMatch::class);
207 $licenseMatch->shouldReceive(
"getLicenseRef")->withNoArgs()->andReturn($licenseRef);
208 $licenseMatch->shouldReceive(
"getAgentRef")->withNoArgs()->andReturn($agentRef);
209 $licenseMatch->shouldReceive(
"getLicenseFileId")->withNoArgs()->andReturn($matchId);
210 $licenseMatch->shouldReceive(
"getPercentage")->withNoArgs()->andReturn($percentage);
211 return array($licenseMatch, $licenseRef, $agentRef);
214 public function testGetScannedLicenses()
217 list($licenseMatch1, $licenseRef1, $agentRef1) = $this->
createLicenseMatch(5,
"licA", 23,
"nomos", 453, null);
222 array(
'id' => 5,
'licenseRef' => $licenseRef1,
'agentRef' => $agentRef1,
'matchId' => 453,
'percentage' => null)
227 $result = $this->agentLicenseEventProcessor->getScannedLicenses($details);
229 assertThat($result, is(array($licenseRef1->getId() => $licenseRef1)));
232 public function testGetScannedLicensesWithEmptyDetails()
234 assertThat($this->agentLicenseEventProcessor->getScannedLicenses(array()), is(emptyArray()));
Handle events related to license findings.
Contains business rules for FOSSology.
testGetScannerDetectedLicenses()
list_t type structure used to keep various lists. (e.g. there are multiple lists).
createLicenseMatch($licenseId, $licenseShortName, $agentId, $agentName, $matchId, $percentage)