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;
52  private $compatibilityDao;
54  private $licenseDao;
55 
56  public function __construct(DbManager $dbManager, AgentDao $agentDao,
57  ClearingDao $clearingDao, UploadDao $uploadDao,
58  HighlightDao $highlightDao, ShowJobsDao $showJobsDao,
59  CopyrightDao $copyrightDao, CompatibilityDao $compatibilityDao,
60  LicenseDao $licenseDao,
61  ClearingDecisionProcessor $clearingDecisionProcessor,
62  AgentLicenseEventProcessor $agentLicenseEventProcessor)
63  {
64  $this->clearingDao = $clearingDao;
65  $this->agentDao = $agentDao;
66  $this->uploadDao = $uploadDao;
67  $this->highlightDao = $highlightDao;
68  $this->showJobsDao = $showJobsDao;
69  $this->copyrightDao = $copyrightDao;
70  $this->dbManager = $dbManager;
71  $this->compatibilityDao = $compatibilityDao;
72  $this->licenseDao = $licenseDao;
73  $this->decisionTypes = new DecisionTypes();
74  $this->clearingDecisionProcessor = $clearingDecisionProcessor;
75  $this->agentLicenseEventProcessor = $agentLicenseEventProcessor;
76  }
77 
82  public function run($uploadId, $userId=2, $groupId=2, $jobId=1, $args="")
83  {
84  $GLOBALS['userId'] = $userId;
85  $GLOBALS['jobId'] = $jobId;
86  $GLOBALS['groupId'] = $groupId;
87 
88  $matches = array();
89 
90  $opts = array();
91  if (preg_match("/-r([0-9]*)/", $args, $matches)) {
92  $opts['r'] = $matches[1];
93  }
94 
95  $GLOBALS['extraOpts'] = $opts;
96 
97  $container = M::mock('Container');
98  $container->shouldReceive('get')->with('db.manager')->andReturn($this->dbManager);
99  $container->shouldReceive('get')->with('dao.agent')->andReturn($this->agentDao);
100  $container->shouldReceive('get')->with('dao.clearing')->andReturn($this->clearingDao);
101  $container->shouldReceive('get')->with('dao.upload')->andReturn($this->uploadDao);
102  $container->shouldReceive('get')->with('dao.highlight')->andReturn($this->highlightDao);
103  $container->shouldReceive('get')->with('dao.show_jobs')->andReturn($this->showJobsDao);
104  $container->shouldReceive('get')->with('dao.copyright')->andReturn($this->copyrightDao);
105  $container->shouldReceive('get')->with('decision.types')->andReturn($this->decisionTypes);
106  $container->shouldReceive('get')->with('businessrules.clearing_decision_processor')->andReturn($this->clearingDecisionProcessor);
107  $container->shouldReceive('get')->with('businessrules.agent_license_event_processor')->andReturn($this->agentLicenseEventProcessor);
108  $container->shouldReceive('get')->with('dao.compatibility')->andReturn($this->compatibilityDao);
109  $container->shouldReceive('get')->with('dao.license')->andReturn($this->licenseDao);
110  $GLOBALS['container'] = $container;
111 
112  $fgetsMock = M::mock(\Fossology\Lib\Agent\FgetsMock::class);
113  $fgetsMock->shouldReceive("fgets")->with(STDIN)->andReturn($uploadId, false);
114  $GLOBALS['fgetsMock'] = $fgetsMock;
115 
116  $exitval = 0;
117 
118  ob_start();
119 
120  include(dirname(dirname(__DIR__)).'/agent/decider.php');
121 
122  $output = ob_get_clean();
123 
124  return array(true, $output, $exitval);
125  }
126 }
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.
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:16
$GLOBALS['xyyzzzDeciderJob']