25 private $itemTreeBounds;
27 private $agentLicenseEventProcessor;
28 private $dbManagerMock;
29 private $latestScanners = array(array(
'agent_pk'=>23,
'agent_name'=>
'nomos'),
30 array(
'agent_pk'=>22,
'agent_name'=>
'monk'));
32 protected function setUp() :
void
34 $this->licenseDao = M::mock(LicenseDao::class);
35 $this->agentsDao = M::mock(AgentDao::class);
37 $this->itemTreeBounds = M::mock(ItemTreeBounds::class);
42 $this->dbManagerMock = M::mock(DbManager::class);
43 $this->dbManagerMock->shouldReceive(
'prepare');
44 $this->dbManagerMock->shouldReceive(
'execute');
45 $this->dbManagerMock->shouldReceive(
'fetchArray')
46 ->andReturn($this->latestScanners[0],$this->latestScanners[1],
false);
47 $this->dbManagerMock->shouldReceive(
'freeResult');
48 $container = M::mock(
'ContainerBuilder');
49 $container->shouldReceive(
'get')->withArgs(array(
'db.manager'))->andReturn($this->dbManagerMock);
52 protected function tearDown() :
void
63 $nomos = $this->latestScanners[0];
64 $monk = $this->latestScanners[1];
65 list($licenseMatch1, $licenseRef1, $agentRef1) = $this->
createLicenseMatch(5,
"licA", $nomos[
'agent_pk'], $nomos[
'agent_name'], 453,
null);
66 list($licenseMatch2, $licenseRef2, $agentRef2) = $this->
createLicenseMatch(5,
"licA", $monk[
'agent_pk'], $monk[
'agent_name'], 665, 95);
67 list($licenseMatch3, $licenseRef3, $agentRef3) = $this->
createLicenseMatch(7,
"licB", $monk[
'agent_pk'], $monk[
'agent_name'], 545, 97);
68 $licenseMatches = array($licenseMatch1, $licenseMatch2, $licenseMatch3);
70 $this->itemTreeBounds->shouldReceive(
'getUploadId')->withNoArgs()->andReturn($uploadId);
71 $this->licenseDao->shouldReceive(
'getAgentFileLicenseMatches')->once()
72 ->withArgs(array($this->itemTreeBounds,LicenseMap::TRIVIAL))
73 ->andReturn($licenseMatches);
74 $scannerDetectedLicenses = $this->agentLicenseEventProcessor->getScannerDetectedLicenses($this->itemTreeBounds);
76 assertThat($scannerDetectedLicenses, is(array(
82 public function testGetScannerDetectedLicenseDetails()
86 $nomos = $this->latestScanners[0];
87 $monk = $this->latestScanners[1];
88 list($licenseMatch1, $licenseRef1, $agentRef1) = $this->
createLicenseMatch($licId,
"licA", $nomos[
'agent_pk'], $nomos[
'agent_name'], 453,
null);
89 list($licenseMatch2, $licenseRef2, $agentRef2) = $this->
createLicenseMatch($licId,
"licA", $monk[
'agent_pk'], $monk[
'agent_name'], 665, 95);
90 $licenseMatches = array($licenseMatch1, $licenseMatch2);
92 $this->itemTreeBounds->shouldReceive(
'getUploadId')->withNoArgs()->andReturn($uploadId);
93 $this->licenseDao->shouldReceive(
'getAgentFileLicenseMatches')->once()
94 ->withArgs(array($this->itemTreeBounds,LicenseMap::TRIVIAL))
95 ->andReturn($licenseMatches);
98 $reflection = new \ReflectionClass($this->agentLicenseEventProcessor);
99 $method = $reflection->getMethod(
'getScannerDetectedLicenseDetails');
100 $method->setAccessible(
true);
101 $latestAgentDetectedLicenses = $method->invoke($this->agentLicenseEventProcessor,$this->itemTreeBounds);
103 assertThat($latestAgentDetectedLicenses, array(
105 array(
'id' => $licId,
'licenseRef' => $licenseRef1,
'agentRef' => $agentRef1,
'matchId' => 453,
'percentage' =>
null)
108 array(
'id' => $licId,
'licenseRef' => $licenseRef2,
'agentRef' => $agentRef2,
'matchId' => 665,
'percentage' => 95)
113 public function testGetScannerDetectedLicenseDetailsWithUnknownAgent()
116 list($licenseMatch1, $licenseRef1, $agentRef1) = $this->
createLicenseMatch(5,
"licA", 23,
"nomos", 453,
null);
117 list($licenseMatch2, $licenseRef2, $agentRef2) = $this->
createLicenseMatch(5,
"licA", 22,
"unknown", 665, 95);
118 $licenseMatches = array($licenseMatch1, $licenseMatch2);
120 $this->itemTreeBounds->shouldReceive(
'getUploadId')->withNoArgs()->andReturn($uploadId);
121 $this->licenseDao->shouldReceive(
'getAgentFileLicenseMatches')->once()
122 ->withArgs(array($this->itemTreeBounds,LicenseMap::TRIVIAL))
123 ->andReturn($licenseMatches);
126 $reflection = new \ReflectionClass($this->agentLicenseEventProcessor);
127 $method = $reflection->getMethod(
'getScannerDetectedLicenseDetails');
128 $method->setAccessible(
true);
129 $latestAgentDetectedLicenses = $method->invoke($this->agentLicenseEventProcessor,$this->itemTreeBounds);
131 assertThat($latestAgentDetectedLicenses, is(array(
134 array(
'id' => 5,
'licenseRef' => $licenseRef1,
'agentRef' => $agentRef1,
'matchId' => 453,
'percentage' =>
null)
140 public function testGetScannerDetectedLicenseDetailsWithOutdatedMatches()
143 list($licenseMatch1, $licenseRef1, $agentRef1) = $this->
createLicenseMatch(5,
"licA", 17,
"nomos", 453,
null);
144 list($licenseMatch2, $licenseRef2, $agentRef2) = $this->
createLicenseMatch(5,
"licA", 18,
"monk", 665, 95);
145 $licenseMatches = array($licenseMatch1, $licenseMatch2);
147 $this->itemTreeBounds->shouldReceive(
'getUploadId')->withNoArgs()->andReturn($uploadId);
148 $this->licenseDao->shouldReceive(
'getAgentFileLicenseMatches')->once()
149 ->withArgs(array($this->itemTreeBounds,LicenseMap::TRIVIAL))
150 ->andReturn($licenseMatches);
153 $reflection = new \ReflectionClass($this->agentLicenseEventProcessor);
154 $method = $reflection->getMethod(
'getScannerDetectedLicenseDetails');
155 $method->setAccessible(
true);
156 $latestAgentDetectedLicenses = $method->invoke($this->agentLicenseEventProcessor,$this->itemTreeBounds);
158 assertThat($latestAgentDetectedLicenses, is(array()));
161 public function testGetScannerDetectedLicenseDetailsNoLicenseFoundShouldBeSkipped()
164 list($licenseMatch1, $licenseRef1, $agentRef1) = $this->
createLicenseMatch(5,
"No_license_found", 23,
"nomos", 453,
null);
165 $licenseMatches = array($licenseMatch1);
167 $this->itemTreeBounds->shouldReceive(
'getUploadId')->withNoArgs()->andReturn($uploadId);
168 $this->licenseDao->shouldReceive(
'getAgentFileLicenseMatches')->once()
169 ->withArgs(array($this->itemTreeBounds,LicenseMap::TRIVIAL))
170 ->andReturn($licenseMatches);
173 $reflection = new \ReflectionClass($this->agentLicenseEventProcessor);
174 $method = $reflection->getMethod(
'getScannerDetectedLicenseDetails');
175 $method->setAccessible(
true);
176 $latestAgentDetectedLicenses = $method->invoke($this->agentLicenseEventProcessor,$this->itemTreeBounds);
178 assertThat($latestAgentDetectedLicenses, is(array()));
184 protected function createLicenseMatch($licenseId, $licenseShortName, $agentId, $agentName, $matchId, $percentage)
186 $licenseRef = M::mock(LicenseRef::class);
187 $licenseRef->shouldReceive(
"getId")->withNoArgs()->andReturn($licenseId);
188 $licenseRef->shouldReceive(
"getShortName")->withNoArgs()->andReturn($licenseShortName);
190 $agentRef = M::mock(LicenseRef::class);
191 $agentRef->shouldReceive(
"getAgentId")->withNoArgs()->andReturn($agentId);
192 $agentRef->shouldReceive(
"getAgentName")->withNoArgs()->andReturn($agentName);
193 $agentRef->shouldReceive(
"getAgentName")->withNoArgs()->andReturn($agentName);
195 $licenseMatch = M::mock(LicenseMatch::class);
196 $licenseMatch->shouldReceive(
"getLicenseRef")->withNoArgs()->andReturn($licenseRef);
197 $licenseMatch->shouldReceive(
"getAgentRef")->withNoArgs()->andReturn($agentRef);
198 $licenseMatch->shouldReceive(
"getLicenseFileId")->withNoArgs()->andReturn($matchId);
199 $licenseMatch->shouldReceive(
"getPercentage")->withNoArgs()->andReturn($percentage);
200 return array($licenseMatch, $licenseRef, $agentRef);
203 public function testGetScannedLicenses()
206 list($licenseMatch1, $licenseRef1, $agentRef1) = $this->
createLicenseMatch(5,
"licA", 23,
"nomos", 453,
null);
211 array(
'id' => 5,
'licenseRef' => $licenseRef1,
'agentRef' => $agentRef1,
'matchId' => 453,
'percentage' =>
null)
216 $result = $this->agentLicenseEventProcessor->getScannedLicenses($details);
218 assertThat($result, is(array($licenseRef1->getId() => $licenseRef1)));
221 public function testGetScannedLicensesWithEmptyDetails()
223 assertThat($this->agentLicenseEventProcessor->getScannedLicenses(array()), is(emptyArray()));
createLicenseMatch($licenseId, $licenseShortName, $agentId, $agentName, $matchId, $percentage)
testGetScannerDetectedLicenses()
Handle events related to license findings.
Contains business rules for FOSSology.
list_t type structure used to keep various lists. (e.g. there are multiple lists).