34 require_once(__DIR__ .
'/../../../lib/php/Test/Agent/AgentTestMockHelper.php');
35 require_once(__DIR__ .
'/../../agent/DeciderAgent.php');
44 private $deciderAgent;
46 private $clearingDecisionProcessor;
49 private $assertCountBefore;
51 protected function setUp():
void
54 $container = M::mock(
'ContainerBuilder');
56 $dbManager = M::mock(DbManager::class);
57 $agentDao = M::mock(AgentDao::class);
58 $agentDao->shouldReceive(
'getCurrentAgentId')->andReturn(1);
60 $this->clearingDecisionProcessor = M::mock(ClearingDecisionProcessor::class);
61 $agentLicenseEventProcessor = M::mock(AgentLicenseEventProcessor::class);
62 $clearingDao = M::mock(ClearingDao::class);
63 $uploadDao = M::mock(UploadDao::class);
64 $highlightDao = M::mock(HighlightDao::class);
65 $showJobsDao =
new ShowJobsDao($dbManager, $uploadDao);
66 $copyrightDao = M::mock(CopyrightDao::class);
67 $compatibilityDao = M::mock(CompatibilityDao::class);
68 $licenseDao = M::mock(LicenseDao::class);
70 $container->shouldReceive(
'get')->with(
'db.manager')->andReturn($dbManager);
71 $container->shouldReceive(
'get')->with(
'dao.agent')->andReturn($agentDao);
72 $container->shouldReceive(
'get')->with(
'dao.highlight')->andReturn($highlightDao);
73 $container->shouldReceive(
'get')->with(
'dao.show_jobs')->andReturn($showJobsDao);
74 $container->shouldReceive(
'get')->with(
'dao.copyright')->andReturn($copyrightDao);
75 $container->shouldReceive(
'get')->with(
'dao.upload')->andReturn($uploadDao);
76 $container->shouldReceive(
'get')->with(
'dao.clearing')->andReturn($clearingDao);
77 $container->shouldReceive(
'get')->with(
'dao.compatibility')->andReturn($compatibilityDao);
78 $container->shouldReceive(
'get')->with(
'dao.license')->andReturn($licenseDao);
79 $container->shouldReceive(
'get')->with(
'decision.types')->andReturn(M::mock(DecisionTypes::class));
80 $container->shouldReceive(
'get')->with(
'businessrules.clearing_decision_processor')
81 ->andReturn($this->clearingDecisionProcessor);
82 $container->shouldReceive(
'get')->with(
'businessrules.agent_license_event_processor')
83 ->andReturn($agentLicenseEventProcessor);
88 $this->licenseMap = M::mock(LicenseMap::class);
89 $this->licenseMap->shouldReceive(
'getProjectedId')->andReturnUsing(
function ($id) {
92 Reflectory::setObjectsProperty($this->deciderAgent,
'licenseMap', $this->licenseMap);
94 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
97 protected function tearDown():
void
99 $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount() - $this->assertCountBefore);
110 $licenseRef =
new LicenseRef($licenseId,
"Lic$licenseId",
"License $licenseId",
"Lic$licenseId");
111 $clearingLicense =
new ClearingLicense($licenseRef, $removed, $eventType);
130 new LicenseRef($licenseId,
"Lic$licenseId",
"License $licenseId",
"Lic$licenseId"),
131 M::mock(AgentRef::class),
149 $result = Reflectory::invokeObjectsMethodnameWith(
151 'autodecideIfKotobaMatchesNoContradiction',
152 [$this->makeItemTreeBounds(), [], []]
154 $this->assertFalse($result);
165 $result = Reflectory::invokeObjectsMethodnameWith(
167 'autodecideIfKotobaMatchesNoContradiction',
168 [$this->makeItemTreeBounds(), [], $events]
170 $this->assertFalse($result);
181 $result = Reflectory::invokeObjectsMethodnameWith(
183 'autodecideIfKotobaMatchesNoContradiction',
184 [$this->makeItemTreeBounds(), [], $events]
186 $this->assertFalse($result);
209 $itemTreeBounds = $this->makeItemTreeBounds();
211 $this->clearingDecisionProcessor->shouldReceive(
'makeDecisionFromLastEvents')
213 ->with($itemTreeBounds, M::any(), M::any(), DecisionTypes::IDENTIFIED,
false);
215 $result = Reflectory::invokeObjectsMethodnameWith(
217 'autodecideIfKotobaMatchesNoContradiction',
218 [$itemTreeBounds, $scannerMatches, $events]
220 $this->assertTrue($result);
246 $this->clearingDecisionProcessor->shouldNotReceive(
'makeDecisionFromLastEvents');
248 $result = Reflectory::invokeObjectsMethodnameWith(
250 'autodecideIfKotobaMatchesNoContradiction',
251 [$this->makeItemTreeBounds(), $scannerMatches, $events]
253 $this->assertFalse($result);
267 $this->clearingDecisionProcessor->shouldReceive(
'makeDecisionFromLastEvents')->once();
269 $result = Reflectory::invokeObjectsMethodnameWith(
271 'autodecideIfKotobaMatchesNoContradiction',
272 [$this->makeItemTreeBounds(), [], $events]
274 $this->assertTrue($result);
288 $this->clearingDecisionProcessor->shouldNotReceive(
'makeDecisionFromLastEvents');
290 $result = Reflectory::invokeObjectsMethodnameWith(
292 'autodecideIfKotobaMatchesNoContradiction',
293 [$this->makeItemTreeBounds(), [], $events]
295 $this->assertFalse($result);
309 $this->clearingDecisionProcessor->shouldReceive(
'makeDecisionFromLastEvents')
311 ->andThrow(
new \Exception(
"candidate license"));
313 $result = Reflectory::invokeObjectsMethodnameWith(
315 'autodecideIfKotobaMatchesNoContradiction',
316 [$this->makeItemTreeBounds(), [], $events]
318 $this->assertFalse($result);
Unit tests for DeciderAgent::autodecideIfKotobaMatchesNoContradiction()
testReturnsFalseWhenMixedKotobaAndHumanEvents()
testReturnsFalseWhenBulkEventPresent()
makeClearingEvent(int $licenseId, int $eventType, bool $removed=false)
testConcludesWhenAllScannerLicensesAccountedFor()
makeScannerMatch(int $licenseId)
testReturnsFalseWhenNoCurrentEvents()
testReturnsFalseWhenDecisionProcessorThrows()
testReturnsFalseWhenHumanEventPresent()
testConcludesWhenNoScannerFindings()
testReturnsFalseWhenScannerFindsUnaccountedLicense()
Agent to decide license findings in an upload.
Handle events related to license findings.
Utility functions to process ClearingDecision.
Wrapper class for license map.
Namespace for decider agent.