FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
SchedulerTestRunnerMock.php
1 <?php
2 /*
3 Copyright (C) 2014-2018, Siemens AG
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 version 2 as published by the Free Software Foundation.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18 
19 namespace Fossology\Decider\Test;
20 
32 use Mockery as M;
33 
34 include_once(__DIR__.'/../../../lib/php/Test/Agent/AgentTestMockHelper.php');
35 include_once(__DIR__.'/SchedulerTestRunner.php');
36 
37 include_once(dirname(dirname(__DIR__)).'/agent/DeciderAgent.php');
38 
40 {
42  private $dbManager;
44  private $clearingDao;
46  private $clearingDecisionProcessor;
48  private $agentLicenseEventProcessor;
50  private $uploadDao;
52  private $agentDao;
54  private $decisionTypes;
56  private $highlightDao;
58  private $showJobsDao;
59 
60  public function __construct(DbManager $dbManager, AgentDao $agentDao, ClearingDao $clearingDao, UploadDao $uploadDao, HighlightDao $highlightDao, ShowJobsDao $showJobsDao, ClearingDecisionProcessor $clearingDecisionProcessor, AgentLicenseEventProcessor $agentLicenseEventProcessor)
61  {
62  $this->clearingDao = $clearingDao;
63  $this->agentDao = $agentDao;
64  $this->uploadDao = $uploadDao;
65  $this->highlightDao = $highlightDao;
66  $this->showJobsDao = $showJobsDao;
67  $this->dbManager = $dbManager;
68  $this->decisionTypes = new DecisionTypes();
69  $this->clearingDecisionProcessor = $clearingDecisionProcessor;
70  $this->agentLicenseEventProcessor = $agentLicenseEventProcessor;
71  }
72 
77  public function run($uploadId, $userId=2, $groupId=2, $jobId=1, $args="")
78  {
79  $GLOBALS['userId'] = $userId;
80  $GLOBALS['jobId'] = $jobId;
81  $GLOBALS['groupId'] = $groupId;
82 
83  $matches = array();
84 
85  $opts = array();
86  if (preg_match("/-r([0-9]*)/", $args, $matches)) {
87  $opts['r'] = $matches[1];
88  }
89 
90  $GLOBALS['extraOpts'] = $opts;
91 
92  $container = M::mock('Container');
93  $container->shouldReceive('get')->with('db.manager')->andReturn($this->dbManager);
94  $container->shouldReceive('get')->with('dao.agent')->andReturn($this->agentDao);
95  $container->shouldReceive('get')->with('dao.clearing')->andReturn($this->clearingDao);
96  $container->shouldReceive('get')->with('dao.upload')->andReturn($this->uploadDao);
97  $container->shouldReceive('get')->with('dao.highlight')->andReturn($this->highlightDao);
98  $container->shouldReceive('get')->with('dao.show_jobs')->andReturn($this->showJobsDao);
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  $GLOBALS['container'] = $container;
103 
104  $fgetsMock = M::mock(\Fossology\Lib\Agent\FgetsMock::class);
105  $fgetsMock->shouldReceive("fgets")->with(STDIN)->andReturn($uploadId, false);
106  $GLOBALS['fgetsMock'] = $fgetsMock;
107 
108  $exitval = 0;
109 
110  ob_start();
111 
112  include(dirname(dirname(__DIR__)).'/agent/decider.php');
113 
114  $output = ob_get_clean();
115 
116  return array(true, $output, $exitval);
117  }
118 }
Structure of an Agent with all required parameters.
Definition: Agent.php:51
Utility functions to process ClearingDecision.
run($uploadId, $userId=2, $groupId=2, $jobId=1, $args="")
Get the arguments required by agent to run and try to run the agent.
$GLOBALS['xyyzzzDeciderJob']
Namespace used by reuser agent.
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:28