FOSSology  4.4.0
Open Source License Compliance by Open Source Software
SchedulerTestRunnerMock.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2014-2018 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 namespace Fossology\Decider\Test;
9 
22 use Mockery as M;
23 
24 include_once(__DIR__.'/../../../lib/php/Test/Agent/AgentTestMockHelper.php');
25 include_once(__DIR__.'/SchedulerTestRunner.php');
26 
27 include_once(dirname(dirname(__DIR__)).'/agent/DeciderAgent.php');
28 
30 {
32  private $dbManager;
34  private $clearingDao;
36  private $clearingDecisionProcessor;
38  private $agentLicenseEventProcessor;
40  private $uploadDao;
42  private $agentDao;
44  private $decisionTypes;
46  private $highlightDao;
48  private $showJobsDao;
50  private $copyrightDao;
51 
52  public function __construct(DbManager $dbManager, AgentDao $agentDao,
53  ClearingDao $clearingDao, UploadDao $uploadDao,
54  HighlightDao $highlightDao, ShowJobsDao $showJobsDao,
55  CopyrightDao $copyrightDao,
56  ClearingDecisionProcessor $clearingDecisionProcessor,
57  AgentLicenseEventProcessor $agentLicenseEventProcessor)
58  {
59  $this->clearingDao = $clearingDao;
60  $this->agentDao = $agentDao;
61  $this->uploadDao = $uploadDao;
62  $this->highlightDao = $highlightDao;
63  $this->showJobsDao = $showJobsDao;
64  $this->copyrightDao = $copyrightDao;
65  $this->dbManager = $dbManager;
66  $this->decisionTypes = new DecisionTypes();
67  $this->clearingDecisionProcessor = $clearingDecisionProcessor;
68  $this->agentLicenseEventProcessor = $agentLicenseEventProcessor;
69  $this->copyrightDao = $copyrightDao;
70  }
71 
76  public function run($uploadId, $userId=2, $groupId=2, $jobId=1, $args="")
77  {
78  $GLOBALS['userId'] = $userId;
79  $GLOBALS['jobId'] = $jobId;
80  $GLOBALS['groupId'] = $groupId;
81 
82  $matches = array();
83 
84  $opts = array();
85  if (preg_match("/-r([0-9]*)/", $args, $matches)) {
86  $opts['r'] = $matches[1];
87  }
88 
89  $GLOBALS['extraOpts'] = $opts;
90 
91  $container = M::mock('Container');
92  $container->shouldReceive('get')->with('db.manager')->andReturn($this->dbManager);
93  $container->shouldReceive('get')->with('dao.agent')->andReturn($this->agentDao);
94  $container->shouldReceive('get')->with('dao.clearing')->andReturn($this->clearingDao);
95  $container->shouldReceive('get')->with('dao.upload')->andReturn($this->uploadDao);
96  $container->shouldReceive('get')->with('dao.highlight')->andReturn($this->highlightDao);
97  $container->shouldReceive('get')->with('dao.show_jobs')->andReturn($this->showJobsDao);
98  $container->shouldReceive('get')->with('dao.copyright')->andReturn($this->copyrightDao);
99  $container->shouldReceive('get')->with('decision.types')->andReturn($this->decisionTypes);
100  $container->shouldReceive('get')->with('businessrules.clearing_decision_processor')->andReturn($this->clearingDecisionProcessor);
101  $container->shouldReceive('get')->with('businessrules.agent_license_event_processor')->andReturn($this->agentLicenseEventProcessor);
102  $container->shouldReceive('get')->with('dao.copyright')->andReturn($this->copyrightDao);
103  $GLOBALS['container'] = $container;
104 
105  $fgetsMock = M::mock(\Fossology\Lib\Agent\FgetsMock::class);
106  $fgetsMock->shouldReceive("fgets")->with(STDIN)->andReturn($uploadId, false);
107  $GLOBALS['fgetsMock'] = $fgetsMock;
108 
109  $exitval = 0;
110 
111  ob_start();
112 
113  include(dirname(dirname(__DIR__)).'/agent/decider.php');
114 
115  $output = ob_get_clean();
116 
117  return array(true, $output, $exitval);
118  }
119 }
Agent to decide license findings in an upload.
run($uploadId, $userId=2, $groupId=2, $jobId=1, $args="")
Get the arguments required by agent to run and try to run the agent.
Structure of an Agent with all required parameters.
Definition: Agent.php:41
Utility functions to process ClearingDecision.
Wrapper class for license map.
Definition: LicenseMap.php:19
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:16
$GLOBALS['xyyzzzDeciderJob']