FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
SchedulerTestRunnerMock.php
1 <?php
2 /*
3 Copyright (C) 2014, 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 
20 
29 use Mockery as M;
30 
31 include_once(__DIR__.'/../../../lib/php/Test/Agent/AgentTestMockHelper.php');
32 include_once(__DIR__.'/SchedulerTestRunner.php');
33 
34 include_once(dirname(dirname(__DIR__)).'/agent/DeciderJobAgent.php');
35 
41 {
43  private $dbManager;
45  private $clearingDao;
47  private $clearingDecisionProcessor;
49  private $agentLicenseEventProcessor;
51  private $uploadDao;
53  private $agentDao;
55  private $decisionTypes;
57  private $highlightDao;
58 
59  public function __construct(DbManager $dbManager, AgentDao $agentDao, ClearingDao $clearingDao, UploadDao $uploadDao, HighlightDao $highlightDao,
60  ClearingDecisionProcessor $clearingDecisionProcessor, AgentLicenseEventProcessor $agentLicenseEventProcessor)
61  {
62  $this->clearingDao = $clearingDao;
63  $this->agentDao = $agentDao;
64  $this->uploadDao = $uploadDao;
65  $this->highlightDao = $highlightDao;
66  $this->dbManager = $dbManager;
67  $this->decisionTypes = new DecisionTypes();
68  $this->clearingDecisionProcessor = $clearingDecisionProcessor;
69  $this->agentLicenseEventProcessor = $agentLicenseEventProcessor;
70  }
71 
81  public function run($uploadId, $userId=2, $groupId=2, $jobId=1, $args="")
82  {
83  $GLOBALS['userId'] = $userId;
84  $GLOBALS['jobId'] = $jobId;
85  $GLOBALS['groupId'] = $groupId;
86 
87  $matches = array();
88 
89  $opts = array();
90  if (preg_match("/-k([0-9]*)/", $args, $matches)) {
91  $opts['k'] = $matches[1];
92  }
93 
94  $GLOBALS['extraOpts'] = $opts;
95 
96  $container = M::mock('Container');
97  $container->shouldReceive('get')->with('db.manager')->andReturn($this->dbManager);
98  $container->shouldReceive('get')->with('dao.agent')->andReturn($this->agentDao);
99  $container->shouldReceive('get')->with('dao.clearing')->andReturn($this->clearingDao);
100  $container->shouldReceive('get')->with('dao.upload')->andReturn($this->uploadDao);
101  $container->shouldReceive('get')->with('dao.highlight')->andReturn($this->highlightDao);
102  $container->shouldReceive('get')->with('decision.types')->andReturn($this->decisionTypes);
103  $container->shouldReceive('get')->with('businessrules.clearing_decision_processor')->andReturn($this->clearingDecisionProcessor);
104  $container->shouldReceive('get')->with('businessrules.agent_license_event_processor')->andReturn($this->agentLicenseEventProcessor);
105  $GLOBALS['container'] = $container;
106 
107  $fgetsMock = M::mock(\Fossology\Lib\Agent\FgetsMock::class);
108  $fgetsMock->shouldReceive("fgets")->with(STDIN)->andReturn($uploadId, false);
109  $GLOBALS['fgetsMock'] = $fgetsMock;
110 
111  $exitval = 0;
112 
113  ob_start();
114 
115  include(dirname(dirname(__DIR__)).'/agent/deciderjob.php');
116 
117  $output = ob_get_clean();
118 
119  return array(true, $output, $exitval);
120  }
121 }
Namespace for decider job test cases.
Interface for scheduler. Called by test case.
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="")
Mock as agent was called from scheduler.
Namespace used by reuser agent.
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:28