36 require_once(__DIR__ .
'/../../../lib/php/Test/Agent/AgentTestMockHelper.php');
37 require_once(__DIR__ .
'/../../agent/DeciderAgent.php');
50 private $clearingDecisionProcessor;
52 private $agentLicenseEventProcessor;
56 private $highlightDao;
67 $container = M::mock(
'ContainerBuilder');
68 $this->
dbManager = M::mock(DbManager::class);
69 $this->agentDao = M::mock(AgentDao::class);
70 $this->agentDao->shouldReceive(
'getCurrentAgentId')->andReturn(1234);
71 $this->highlightDao = M::mock(HighlightDao::class);
72 $this->uploadDao = M::mock(UploadDao::class);
74 $this->clearingDao = M::mock(ClearingDao::class);
75 $this->clearingDecisionProcessor = M::mock(ClearingDecisionProcessor::class);
76 $this->agentLicenseEventProcessor = M::mock(AgentLicenseEventProcessor::class);
78 $container->shouldReceive(
'get')->withArgs(array(
'db.manager'))->andReturn($this->
dbManager);
79 $container->shouldReceive(
'get')->withArgs(array(
'dao.agent'))->andReturn($this->agentDao);
80 $container->shouldReceive(
'get')->with(
'dao.highlight')->andReturn($this->highlightDao);
81 $container->shouldReceive(
'get')->with(
'dao.show_jobs')->andReturn($this->showJobsDao);
82 $container->shouldReceive(
'get')->withArgs(array(
'dao.upload'))->andReturn($this->uploadDao);
83 $container->shouldReceive(
'get')->withArgs(array(
'dao.clearing'))->andReturn($this->clearingDao);
84 $container->shouldReceive(
'get')->withArgs(array(
'decision.types'))->andReturn(M::mock(DecisionTypes::class));
85 $container->shouldReceive(
'get')->withArgs(array(
'businessrules.clearing_decision_processor'))->andReturn($this->clearingDecisionProcessor);
86 $container->shouldReceive(
'get')->withArgs(array(
'businessrules.agent_license_event_processor'))->andReturn($this->agentLicenseEventProcessor);
87 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
96 $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
110 $reflection = new \ReflectionClass($deciderAgent);
111 $method = $reflection->getMethod(
'areNomosMatchesInsideAMonkMatch');
112 $method->setAccessible(
true);
114 $licenseMatches = array();
115 assertThat( $method->invoke($deciderAgent,$licenseMatches), equalTo(
false) );
128 $reflection = new \ReflectionClass($deciderAgent);
129 $method = $reflection->getMethod(
'areNomosMatchesInsideAMonkMatch');
130 $method->setAccessible(
true);
132 $this->highlightDao->shouldReceive(
'getHighlightRegion')->andReturn(array($start=2, $end=5));
133 $licenseMatches = array(
'nomos'=>
136 assertThat( $method->invoke($deciderAgent,$licenseMatches), equalTo(
false) );
149 $reflection = new \ReflectionClass($deciderAgent);
150 $method = $reflection->getMethod(
'areNomosMatchesInsideAMonkMatch');
151 $method->setAccessible(
true);
153 $this->highlightDao->shouldReceive(
'getHighlightRegion')->andReturn(array($start=2, $end=5));
154 $licenseMatches = array(
'monk'=>
157 assertThat( $method->invoke($deciderAgent,$licenseMatches), equalTo(
false) );
172 $reflection = new \ReflectionClass($deciderAgent);
173 $method = $reflection->getMethod(
'areNomosMatchesInsideAMonkMatch');
174 $method->setAccessible(
true);
177 $this->highlightDao->shouldReceive(
'getHighlightRegion')->with($monkId)->andReturn(array($start=2, $end=5));
178 $this->highlightDao->shouldReceive(
'getHighlightRegion')->with($nomosId)->andReturn(array($start=2, $end=8));
181 assertThat( $method->invoke($deciderAgent,$licenseMatches), equalTo(
false) );
195 $reflection = new \ReflectionClass($deciderAgent);
196 $method = $reflection->getMethod(
'areNomosMatchesInsideAMonkMatch');
197 $method->setAccessible(
true);
200 $this->highlightDao->shouldReceive(
'getHighlightRegion')->with($monkId)->andReturn(array($start=2, $end=5));
201 $this->highlightDao->shouldReceive(
'getHighlightRegion')->with($nomosId)->andReturn(array($start=4, $end=5));
204 assertThat( $method->invoke($deciderAgent,$licenseMatches), equalTo(
true) );
217 $licenseMatch = M::mock(LicenseMatch::class);
218 $licenseMatch->shouldReceive(
"getLicenseFileId")->withNoArgs()->andReturn($matchId);
219 return $licenseMatch;
234 $agree = Reflectory::invokeObjectsMethodnameWith($deciderAgent,
'areNomosMonkNinkaAgreed', array($licenseMatches));
235 assertThat($agree, equalTo(
false) );
252 $agree = Reflectory::invokeObjectsMethodnameWith($deciderAgent,
'areNomosMonkNinkaAgreed', array($licenseMatches));
253 assertThat($agree, equalTo(
true) );
272 $agree = Reflectory::invokeObjectsMethodnameWith($deciderAgent,
'areNomosMonkNinkaAgreed', array($licenseMatches));
273 assertThat($agree, equalTo(
false) );
284 $licenseMatch = M::mock(LicenseMatch::class);
285 $licenseMatch->shouldReceive(
"getLicenseId")->withNoArgs()->andReturn($licId);
286 return $licenseMatch;
testAreNomosMonkNinkaAgreed_notIfOnlyTwoOfThem()
testAreNomosMonkNinkaAgreed_notIfAnyOther()
createLicenseMatchWithLicId($licId)
Create mock LicenseMatch object with getLicenseId returning $licId.
Namespace for decider agent.
Agent to decide license findings in an upload.
testAreNomosMatchesInsideAMonkMatchIfNoNomos()
testAreNomosMatchesInsideAMonkMatchIfNoneAtAll()
testAreNomosMonkNinkaAgreed_alsoMultiMatch()
setUp()
Setup test objects, database and repo.
tearDown()
Remove test objects.
fo_dbManager * dbManager
fo_dbManager object
testAreNomosMatchesInsideAMonkMatchIfNotFit()
createLicenseMatch($agentName, $matchId)
Create mock LicenseMatch object with getLicenseFileId returning $matchId.
testAreNomosMatchesInsideAMonkMatchIfNoMonk()
testAreNomosMatchesInsideAMonkMatchIfFit()