26 require_once(__DIR__ .
'/../../../lib/php/Test/Agent/AgentTestMockHelper.php');
27 require_once(__DIR__ .
'/../../agent/DeciderAgent.php');
40 private $clearingDecisionProcessor;
42 private $agentLicenseEventProcessor;
46 private $highlightDao;
50 private $copyrightDao;
56 protected function setUp() : void
59 $container = M::mock(
'ContainerBuilder');
60 $this->
dbManager = M::mock(DbManager::class);
61 $this->agentDao = M::mock(AgentDao::class);
62 $this->agentDao->shouldReceive(
'getCurrentAgentId')->andReturn(1234);
63 $this->highlightDao = M::mock(HighlightDao::class);
64 $this->uploadDao = M::mock(UploadDao::class);
65 $this->copyrightDao = M::mock(CopyrightDao::class);
67 $this->copyrightDao = M::mock(CopyrightDao::class);
68 $this->clearingDao = M::mock(ClearingDao::class);
69 $this->clearingDecisionProcessor = M::mock(ClearingDecisionProcessor::class);
70 $this->agentLicenseEventProcessor = M::mock(AgentLicenseEventProcessor::class);
72 $container->shouldReceive(
'get')->withArgs(array(
'db.manager'))->andReturn($this->
dbManager);
73 $container->shouldReceive(
'get')->withArgs(array(
'dao.agent'))->andReturn($this->agentDao);
74 $container->shouldReceive(
'get')->with(
'dao.highlight')->andReturn($this->highlightDao);
75 $container->shouldReceive(
'get')->with(
'dao.show_jobs')->andReturn($this->showJobsDao);
76 $container->shouldReceive(
'get')->with(
'dao.copyright')->andReturn($this->copyrightDao);
77 $container->shouldReceive(
'get')->withArgs(array(
'dao.upload'))->andReturn($this->uploadDao);
78 $container->shouldReceive(
'get')->withArgs(array(
'dao.copyright'))->andReturn($this->copyrightDao);
79 $container->shouldReceive(
'get')->withArgs(array(
'dao.clearing'))->andReturn($this->clearingDao);
80 $container->shouldReceive(
'get')->withArgs(array(
'decision.types'))->andReturn(M::mock(DecisionTypes::class));
81 $container->shouldReceive(
'get')->withArgs(array(
'businessrules.clearing_decision_processor'))->andReturn($this->clearingDecisionProcessor);
82 $container->shouldReceive(
'get')->withArgs(array(
'businessrules.agent_license_event_processor'))->andReturn($this->agentLicenseEventProcessor);
83 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
92 $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
106 $reflection = new \ReflectionClass($deciderAgent);
107 $method = $reflection->getMethod(
'areNomosMatchesInsideAMonkMatch');
108 $method->setAccessible(
true);
110 $licenseMatches = array();
111 assertThat( $method->invoke($deciderAgent,$licenseMatches), equalTo(
false) );
124 $reflection = new \ReflectionClass($deciderAgent);
125 $method = $reflection->getMethod(
'areNomosMatchesInsideAMonkMatch');
126 $method->setAccessible(
true);
128 $this->highlightDao->shouldReceive(
'getHighlightRegion')->andReturn(array($start=2, $end=5));
129 $licenseMatches = array(
'nomos'=>
132 assertThat( $method->invoke($deciderAgent,$licenseMatches), equalTo(
false) );
145 $reflection = new \ReflectionClass($deciderAgent);
146 $method = $reflection->getMethod(
'areNomosMatchesInsideAMonkMatch');
147 $method->setAccessible(
true);
149 $this->highlightDao->shouldReceive(
'getHighlightRegion')->andReturn(array($start=2, $end=5));
150 $licenseMatches = array(
'monk'=>
153 assertThat( $method->invoke($deciderAgent,$licenseMatches), equalTo(
false) );
168 $reflection = new \ReflectionClass($deciderAgent);
169 $method = $reflection->getMethod(
'areNomosMatchesInsideAMonkMatch');
170 $method->setAccessible(
true);
173 $this->highlightDao->shouldReceive(
'getHighlightRegion')->with($monkId)->andReturn(array($start=2, $end=5));
174 $this->highlightDao->shouldReceive(
'getHighlightRegion')->with($nomosId)->andReturn(array($start=2, $end=8));
177 assertThat( $method->invoke($deciderAgent,$licenseMatches), equalTo(
false) );
191 $reflection = new \ReflectionClass($deciderAgent);
192 $method = $reflection->getMethod(
'areNomosMatchesInsideAMonkMatch');
193 $method->setAccessible(
true);
196 $this->highlightDao->shouldReceive(
'getHighlightRegion')->with($monkId)->andReturn(array($start=2, $end=5));
197 $this->highlightDao->shouldReceive(
'getHighlightRegion')->with($nomosId)->andReturn(array($start=4, $end=5));
200 assertThat( $method->invoke($deciderAgent,$licenseMatches), equalTo(
true) );
213 $licenseMatch = M::mock(LicenseMatch::class);
214 $licenseMatch->shouldReceive(
"getLicenseFileId")->withNoArgs()->andReturn($matchId);
215 return $licenseMatch;
230 $agree = Reflectory::invokeObjectsMethodnameWith($deciderAgent,
'areNomosMonkNinkaAgreed', array($licenseMatches));
231 assertThat($agree, equalTo(
false) );
248 $agree = Reflectory::invokeObjectsMethodnameWith($deciderAgent,
'areNomosMonkNinkaAgreed', array($licenseMatches));
249 assertThat($agree, equalTo(
true) );
268 $agree = Reflectory::invokeObjectsMethodnameWith($deciderAgent,
'areNomosMonkNinkaAgreed', array($licenseMatches));
269 assertThat($agree, equalTo(
false) );
280 $licenseMatch = M::mock(LicenseMatch::class);
281 $licenseMatch->shouldReceive(
"getLicenseId")->withNoArgs()->andReturn($licId);
282 return $licenseMatch;
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.
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.