31 require_once(__DIR__ .
'/../../../lib/php/Test/Agent/AgentTestMockHelper.php');
32 require_once(__DIR__ .
'/../../agent/DeciderAgent.php');
45 private $clearingDecisionProcessor;
47 private $agentLicenseEventProcessor;
51 private $highlightDao;
55 private $copyrightDao;
57 private $compatibilityDao;
65 protected function setUp() : void
68 $container = M::mock(
'ContainerBuilder');
69 $this->
dbManager = M::mock(DbManager::class);
70 $this->agentDao = M::mock(AgentDao::class);
71 $this->agentDao->shouldReceive(
'getCurrentAgentId')->andReturn(1234);
72 $this->highlightDao = M::mock(HighlightDao::class);
73 $this->uploadDao = M::mock(UploadDao::class);
74 $this->copyrightDao = M::mock(CopyrightDao::class);
76 $this->copyrightDao = M::mock(CopyrightDao::class);
77 $this->clearingDao = M::mock(ClearingDao::class);
78 $this->compatibilityDao = M::mock(CompatibilityDao::class);
79 $this->licenseDao = M::mock(LicenseDao::class);
80 $this->clearingDecisionProcessor = M::mock(ClearingDecisionProcessor::class);
81 $this->agentLicenseEventProcessor = M::mock(AgentLicenseEventProcessor::class);
83 $container->shouldReceive(
'get')->withArgs(array(
'db.manager'))->andReturn($this->
dbManager);
84 $container->shouldReceive(
'get')->withArgs(array(
'dao.agent'))->andReturn($this->agentDao);
85 $container->shouldReceive(
'get')->with(
'dao.highlight')->andReturn($this->highlightDao);
86 $container->shouldReceive(
'get')->with(
'dao.show_jobs')->andReturn($this->showJobsDao);
87 $container->shouldReceive(
'get')->with(
'dao.copyright')->andReturn($this->copyrightDao);
88 $container->shouldReceive(
'get')->withArgs(array(
'dao.upload'))->andReturn($this->uploadDao);
89 $container->shouldReceive(
'get')->withArgs(array(
'dao.copyright'))->andReturn($this->copyrightDao);
90 $container->shouldReceive(
'get')->withArgs(array(
'dao.clearing'))->andReturn($this->clearingDao);
91 $container->shouldReceive(
'get')->withArgs(array(
'dao.compatibility'))->andReturn($this->compatibilityDao);
92 $container->shouldReceive(
'get')->withArgs(array(
'dao.license'))->andReturn($this->licenseDao);
93 $container->shouldReceive(
'get')->withArgs(array(
'decision.types'))->andReturn(M::mock(DecisionTypes::class));
94 $container->shouldReceive(
'get')->withArgs(array(
'businessrules.clearing_decision_processor'))->andReturn($this->clearingDecisionProcessor);
95 $container->shouldReceive(
'get')->withArgs(array(
'businessrules.agent_license_event_processor'))->andReturn($this->agentLicenseEventProcessor);
96 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
105 $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
119 $reflection = new \ReflectionClass($deciderAgent);
120 $method = $reflection->getMethod(
'areNomosMatchesInsideAMonkMatch');
121 $method->setAccessible(
true);
123 $licenseMatches = array();
124 assertThat( $method->invoke($deciderAgent,$licenseMatches), equalTo(
false) );
137 $reflection = new \ReflectionClass($deciderAgent);
138 $method = $reflection->getMethod(
'areNomosMatchesInsideAMonkMatch');
139 $method->setAccessible(
true);
141 $this->highlightDao->shouldReceive(
'getHighlightRegion')->andReturn(array($start=2, $end=5));
142 $licenseMatches = array(
'nomos'=>
145 assertThat( $method->invoke($deciderAgent,$licenseMatches), equalTo(
false) );
158 $reflection = new \ReflectionClass($deciderAgent);
159 $method = $reflection->getMethod(
'areNomosMatchesInsideAMonkMatch');
160 $method->setAccessible(
true);
162 $this->highlightDao->shouldReceive(
'getHighlightRegion')->andReturn(array($start=2, $end=5));
163 $licenseMatches = array(
'monk'=>
166 assertThat( $method->invoke($deciderAgent,$licenseMatches), equalTo(
false) );
181 $reflection = new \ReflectionClass($deciderAgent);
182 $method = $reflection->getMethod(
'areNomosMatchesInsideAMonkMatch');
183 $method->setAccessible(
true);
186 $this->highlightDao->shouldReceive(
'getHighlightRegion')->with($monkId)->andReturn(array($start=2, $end=5));
187 $this->highlightDao->shouldReceive(
'getHighlightRegion')->with($nomosId)->andReturn(array($start=2, $end=8));
190 assertThat( $method->invoke($deciderAgent,$licenseMatches), equalTo(
false) );
204 $reflection = new \ReflectionClass($deciderAgent);
205 $method = $reflection->getMethod(
'areNomosMatchesInsideAMonkMatch');
206 $method->setAccessible(
true);
209 $this->highlightDao->shouldReceive(
'getHighlightRegion')->with($monkId)->andReturn(array($start=2, $end=5));
210 $this->highlightDao->shouldReceive(
'getHighlightRegion')->with($nomosId)->andReturn(array($start=4, $end=5));
213 assertThat( $method->invoke($deciderAgent,$licenseMatches), equalTo(
true) );
226 $licenseMatch = M::mock(LicenseMatch::class);
227 $licenseMatch->shouldReceive(
"getLicenseFileId")->withNoArgs()->andReturn($matchId);
228 return $licenseMatch;
243 $agree = Reflectory::invokeObjectsMethodnameWith($deciderAgent,
'areNomosMonkNinkaAgreed', array($licenseMatches));
244 assertThat($agree, equalTo(
false) );
261 $agree = Reflectory::invokeObjectsMethodnameWith($deciderAgent,
'areNomosMonkNinkaAgreed', array($licenseMatches));
262 assertThat($agree, equalTo(
true) );
281 $agree = Reflectory::invokeObjectsMethodnameWith($deciderAgent,
'areNomosMonkNinkaAgreed', array($licenseMatches));
282 assertThat($agree, equalTo(
false) );
294 $licenseShortName =
"LicA";
295 $licenseName =
"LicenseA";
297 $licenseShortName =
"LicB";
298 $licenseName =
"LicenseB";
301 new LicenseRef($licId, $licenseShortName, $licenseName, $licenseShortName),
302 M::mock(AgentRef::class),
336 $itemTreeBounds =
new ItemTreeBounds(123,
"uploadtree",
"2", 1, 4);
338 $this->compatibilityDao->shouldReceive(
"getCompatibilityForFile")
345 $this->compatibilityDao->shouldReceive(
"getCompatibilityForFile")
353 $agree = Reflectory::invokeObjectsMethodnameWith($deciderAgent,
354 'noLicenseConflict', [$itemTreeBounds, $licenseMatches]);
355 $this->assertTrue($agree,
"Wrong result for compatible licenses");
388 $itemTreeBounds =
new ItemTreeBounds(123,
"uploadtree",
"2", 1, 4);
390 $this->compatibilityDao->shouldReceive(
"getCompatibilityForFile")
397 $this->compatibilityDao->shouldReceive(
"getCompatibilityForFile")
405 $agree = Reflectory::invokeObjectsMethodnameWith($deciderAgent,
406 'noLicenseConflict', [$itemTreeBounds, $licenseMatches]);
407 $this->assertFalse($agree,
"Wrong result for incompatible licenses");
441 $this->licenseDao->shouldReceive(
"getLicenseType")
442 ->withArgs([$licId])->andReturn(
"Permissive");
443 $this->licenseDao->shouldReceive(
"getLicenseType")
444 ->withArgs([$otherLicId])->andReturn(
"Permissive");
446 $reflector = new \ReflectionProperty(DeciderAgent::class,
"licenseType");
447 $reflector->setAccessible(
true);
448 $reflector->setValue($deciderAgent,
"Permissive");
450 $agree = Reflectory::invokeObjectsMethodnameWith($deciderAgent,
451 'allLicenseInType', [$licenseMatches]);
452 $this->assertTrue($agree,
"Wrong result for compatible license types");
486 $this->licenseDao->shouldReceive(
"getLicenseType")
487 ->withArgs([$licId])->andReturn(
"Permissive");
488 $this->licenseDao->shouldReceive(
"getLicenseType")
489 ->withArgs([$otherLicId])->andReturn(
"Copyleft");
491 $reflector = new \ReflectionProperty(DeciderAgent::class,
"licenseType");
492 $reflector->setAccessible(
true);
493 $reflector->setValue($deciderAgent,
"Permissive");
495 $agree = Reflectory::invokeObjectsMethodnameWith($deciderAgent,
496 'allLicenseInType', [$licenseMatches]);
497 $this->assertFalse($agree,
"Wrong result for non-compatible license types");
testnoLicenseConflict_twoOfThem()
testallLicenseInType_twoOfThem()
testnoLicenseConflict_twoOfThemNotComp()
testAreNomosMatchesInsideAMonkMatchIfNoNomos()
testAreNomosMonkNinkaAgreed_alsoMultiMatch()
createLicenseMatchWithLicId($licId)
Create mock LicenseMatch object with getLicenseId returning $licId.
testAreNomosMonkNinkaAgreed_notIfAnyOther()
tearDown()
Remove test objects.
testAreNomosMatchesInsideAMonkMatchIfNotFit()
testAreNomosMatchesInsideAMonkMatchIfNoMonk()
testAreNomosMatchesInsideAMonkMatchIfFit()
testAreNomosMonkNinkaAgreed_notIfOnlyTwoOfThem()
testAreNomosMatchesInsideAMonkMatchIfNoneAtAll()
setUp()
Setup test objects, database and repo.
createLicenseMatch($agentName, $matchId)
Create mock LicenseMatch object with getLicenseFileId returning $matchId.
testallLicenseInType_twoOfThemNonComp()
Agent to decide license findings in an upload.
Handle events related to license findings.
Utility functions to process ClearingDecision.
fo_dbManager * dbManager
fo_dbManager object
Namespace for decider agent.