31 require_once(__DIR__ .
'/../../../lib/php/Test/Agent/AgentTestMockHelper.php');
32 require_once(__DIR__ .
'/../../agent/DeciderAgent.php');
41 public $assertCountBefore;
48 private $clearingDecisionProcessor;
50 private $agentLicenseEventProcessor;
54 private $highlightDao;
58 private $copyrightDao;
60 private $compatibilityDao;
68 protected function setUp() : void
71 $container = M::mock(
'ContainerBuilder');
72 $this->
dbManager = M::mock(DbManager::class);
73 $this->agentDao = M::mock(AgentDao::class);
74 $this->agentDao->shouldReceive(
'getCurrentAgentId')->andReturn(1234);
75 $this->highlightDao = M::mock(HighlightDao::class);
76 $this->uploadDao = M::mock(UploadDao::class);
77 $this->copyrightDao = M::mock(CopyrightDao::class);
79 $this->copyrightDao = M::mock(CopyrightDao::class);
80 $this->clearingDao = M::mock(ClearingDao::class);
81 $this->compatibilityDao = M::mock(CompatibilityDao::class);
82 $this->licenseDao = M::mock(LicenseDao::class);
83 $this->clearingDecisionProcessor = M::mock(ClearingDecisionProcessor::class);
84 $this->agentLicenseEventProcessor = M::mock(AgentLicenseEventProcessor::class);
86 $container->shouldReceive(
'get')->withArgs(array(
'db.manager'))->andReturn($this->
dbManager);
87 $container->shouldReceive(
'get')->withArgs(array(
'dao.agent'))->andReturn($this->agentDao);
88 $container->shouldReceive(
'get')->with(
'dao.highlight')->andReturn($this->highlightDao);
89 $container->shouldReceive(
'get')->with(
'dao.show_jobs')->andReturn($this->showJobsDao);
90 $container->shouldReceive(
'get')->with(
'dao.copyright')->andReturn($this->copyrightDao);
91 $container->shouldReceive(
'get')->withArgs(array(
'dao.upload'))->andReturn($this->uploadDao);
92 $container->shouldReceive(
'get')->withArgs(array(
'dao.copyright'))->andReturn($this->copyrightDao);
93 $container->shouldReceive(
'get')->withArgs(array(
'dao.clearing'))->andReturn($this->clearingDao);
94 $container->shouldReceive(
'get')->withArgs(array(
'dao.compatibility'))->andReturn($this->compatibilityDao);
95 $container->shouldReceive(
'get')->withArgs(array(
'dao.license'))->andReturn($this->licenseDao);
96 $container->shouldReceive(
'get')->withArgs(array(
'decision.types'))->andReturn(M::mock(DecisionTypes::class));
97 $container->shouldReceive(
'get')->withArgs(array(
'businessrules.clearing_decision_processor'))->andReturn($this->clearingDecisionProcessor);
98 $container->shouldReceive(
'get')->withArgs(array(
'businessrules.agent_license_event_processor'))->andReturn($this->agentLicenseEventProcessor);
99 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
108 $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
122 $reflection = new \ReflectionClass($deciderAgent);
123 $method = $reflection->getMethod(
'areNomosMatchesInsideAMonkMatch');
124 $method->setAccessible(
true);
126 $licenseMatches = array();
127 assertThat( $method->invoke($deciderAgent,$licenseMatches), equalTo(
false) );
140 $reflection = new \ReflectionClass($deciderAgent);
141 $method = $reflection->getMethod(
'areNomosMatchesInsideAMonkMatch');
142 $method->setAccessible(
true);
144 $this->highlightDao->shouldReceive(
'getHighlightRegion')->andReturn(array($start=2, $end=5));
145 $licenseMatches = array(
'nomos'=>
148 assertThat( $method->invoke($deciderAgent,$licenseMatches), equalTo(
false) );
161 $reflection = new \ReflectionClass($deciderAgent);
162 $method = $reflection->getMethod(
'areNomosMatchesInsideAMonkMatch');
163 $method->setAccessible(
true);
165 $this->highlightDao->shouldReceive(
'getHighlightRegion')->andReturn(array($start=2, $end=5));
166 $licenseMatches = array(
'monk'=>
169 assertThat( $method->invoke($deciderAgent,$licenseMatches), equalTo(
false) );
184 $reflection = new \ReflectionClass($deciderAgent);
185 $method = $reflection->getMethod(
'areNomosMatchesInsideAMonkMatch');
186 $method->setAccessible(
true);
189 $this->highlightDao->shouldReceive(
'getHighlightRegion')->with($monkId)->andReturn(array($start=2, $end=5));
190 $this->highlightDao->shouldReceive(
'getHighlightRegion')->with($nomosId)->andReturn(array($start=2, $end=8));
193 assertThat( $method->invoke($deciderAgent,$licenseMatches), equalTo(
false) );
207 $reflection = new \ReflectionClass($deciderAgent);
208 $method = $reflection->getMethod(
'areNomosMatchesInsideAMonkMatch');
209 $method->setAccessible(
true);
212 $this->highlightDao->shouldReceive(
'getHighlightRegion')->with($monkId)->andReturn(array($start=2, $end=5));
213 $this->highlightDao->shouldReceive(
'getHighlightRegion')->with($nomosId)->andReturn(array($start=4, $end=5));
216 assertThat( $method->invoke($deciderAgent,$licenseMatches), equalTo(
true) );
229 $licenseMatch = M::mock(LicenseMatch::class);
230 $licenseMatch->shouldReceive(
"getLicenseFileId")->withNoArgs()->andReturn($matchId);
231 return $licenseMatch;
246 $agree = Reflectory::invokeObjectsMethodnameWith($deciderAgent,
'areNomosMonkNinkaAgreed', array($licenseMatches));
247 assertThat($agree, equalTo(
false) );
264 $agree = Reflectory::invokeObjectsMethodnameWith($deciderAgent,
'areNomosMonkNinkaAgreed', array($licenseMatches));
265 assertThat($agree, equalTo(
true) );
284 $agree = Reflectory::invokeObjectsMethodnameWith($deciderAgent,
'areNomosMonkNinkaAgreed', array($licenseMatches));
285 assertThat($agree, equalTo(
false) );
297 $licenseShortName =
"LicA";
298 $licenseName =
"LicenseA";
300 $licenseShortName =
"LicB";
301 $licenseName =
"LicenseB";
304 new LicenseRef($licId, $licenseShortName, $licenseName, $licenseShortName),
305 M::mock(AgentRef::class),
339 $itemTreeBounds =
new ItemTreeBounds(123,
"uploadtree",
"2", 1, 4);
341 $this->compatibilityDao->shouldReceive(
"getCompatibilityForFile")
348 $this->compatibilityDao->shouldReceive(
"getCompatibilityForFile")
356 $agree = Reflectory::invokeObjectsMethodnameWith($deciderAgent,
357 'noLicenseConflict', [$itemTreeBounds, $licenseMatches]);
358 $this->assertTrue($agree,
"Wrong result for compatible licenses");
391 $itemTreeBounds =
new ItemTreeBounds(123,
"uploadtree",
"2", 1, 4);
393 $this->compatibilityDao->shouldReceive(
"getCompatibilityForFile")
400 $this->compatibilityDao->shouldReceive(
"getCompatibilityForFile")
408 $agree = Reflectory::invokeObjectsMethodnameWith($deciderAgent,
409 'noLicenseConflict', [$itemTreeBounds, $licenseMatches]);
410 $this->assertFalse($agree,
"Wrong result for incompatible licenses");
444 $this->licenseDao->shouldReceive(
"getLicenseType")
445 ->withArgs([$licId])->andReturn(
"Permissive");
446 $this->licenseDao->shouldReceive(
"getLicenseType")
447 ->withArgs([$otherLicId])->andReturn(
"Permissive");
449 $reflector = new \ReflectionProperty(DeciderAgent::class,
"licenseType");
450 $reflector->setAccessible(
true);
451 $reflector->setValue($deciderAgent,
"Permissive");
453 $agree = Reflectory::invokeObjectsMethodnameWith($deciderAgent,
454 'allLicenseInType', [$licenseMatches]);
455 $this->assertTrue($agree,
"Wrong result for compatible license types");
489 $this->licenseDao->shouldReceive(
"getLicenseType")
490 ->withArgs([$licId])->andReturn(
"Permissive");
491 $this->licenseDao->shouldReceive(
"getLicenseType")
492 ->withArgs([$otherLicId])->andReturn(
"Copyleft");
494 $reflector = new \ReflectionProperty(DeciderAgent::class,
"licenseType");
495 $reflector->setAccessible(
true);
496 $reflector->setValue($deciderAgent,
"Permissive");
498 $agree = Reflectory::invokeObjectsMethodnameWith($deciderAgent,
499 'allLicenseInType', [$licenseMatches]);
500 $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.