FOSSology  4.4.0
Open Source License Compliance by Open Source Software
SchedulerTestRunnerMock.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2014 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
9 
18 use Mockery as M;
19 
20 include_once(__DIR__.'/../../../lib/php/Test/Agent/AgentTestMockHelper.php');
21 include_once(__DIR__.'/SchedulerTestRunner.php');
22 
23 include_once(dirname(dirname(__DIR__)).'/agent/DeciderJobAgent.php');
24 
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;
47 
48  public function __construct(DbManager $dbManager, AgentDao $agentDao, ClearingDao $clearingDao, UploadDao $uploadDao, HighlightDao $highlightDao,
49  ClearingDecisionProcessor $clearingDecisionProcessor, AgentLicenseEventProcessor $agentLicenseEventProcessor)
50  {
51  $this->clearingDao = $clearingDao;
52  $this->agentDao = $agentDao;
53  $this->uploadDao = $uploadDao;
54  $this->highlightDao = $highlightDao;
55  $this->dbManager = $dbManager;
56  $this->decisionTypes = new DecisionTypes();
57  $this->clearingDecisionProcessor = $clearingDecisionProcessor;
58  $this->agentLicenseEventProcessor = $agentLicenseEventProcessor;
59  }
60 
70  public function run($uploadId, $userId=2, $groupId=2, $jobId=1, $args="")
71  {
72  $GLOBALS['userId'] = $userId;
73  $GLOBALS['jobId'] = $jobId;
74  $GLOBALS['groupId'] = $groupId;
75 
76  $matches = array();
77 
78  $opts = array();
79  if (preg_match("/-k([0-9]*)/", $args, $matches)) {
80  $opts['k'] = $matches[1];
81  }
82 
83  $GLOBALS['extraOpts'] = $opts;
84 
85  $container = M::mock('Container');
86  $container->shouldReceive('get')->with('db.manager')->andReturn($this->dbManager);
87  $container->shouldReceive('get')->with('dao.agent')->andReturn($this->agentDao);
88  $container->shouldReceive('get')->with('dao.clearing')->andReturn($this->clearingDao);
89  $container->shouldReceive('get')->with('dao.upload')->andReturn($this->uploadDao);
90  $container->shouldReceive('get')->with('dao.highlight')->andReturn($this->highlightDao);
91  $container->shouldReceive('get')->with('decision.types')->andReturn($this->decisionTypes);
92  $container->shouldReceive('get')->with('businessrules.clearing_decision_processor')->andReturn($this->clearingDecisionProcessor);
93  $container->shouldReceive('get')->with('businessrules.agent_license_event_processor')->andReturn($this->agentLicenseEventProcessor);
94  $GLOBALS['container'] = $container;
95 
96  $fgetsMock = M::mock(\Fossology\Lib\Agent\FgetsMock::class);
97  $fgetsMock->shouldReceive("fgets")->with(STDIN)->andReturn($uploadId, false);
98  $GLOBALS['fgetsMock'] = $fgetsMock;
99 
100  $exitval = 0;
101 
102  ob_start();
103 
104  include(dirname(dirname(__DIR__)).'/agent/deciderjob.php');
105 
106  $output = ob_get_clean();
107 
108  return array(true, $output, $exitval);
109  }
110 }
run($uploadId, $userId=2, $groupId=2, $jobId=1, $args="")
Mock as agent was called from scheduler.
Structure of an Agent with all required parameters.
Definition: Agent.php:41
Utility functions to process ClearingDecision.
Interface for scheduler. Called by test case.
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:16
Namespace for decider job test cases.