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 
19 namespace Fossology\Reuser\Test;
20 
30 use Mockery as M;
31 
32 include_once(__DIR__.'/../../../lib/php/Test/Agent/AgentTestMockHelper.php');
33 include_once(__DIR__.'/SchedulerTestRunner.php');
34 
35 include(dirname(dirname(__DIR__)).'/agent/ReuserAgent.php');
36 
42 {
46  private $dbManager;
47 
51  private $clearingDao;
63  private $uploadDao;
67  private $agentDao;
71  private $treeDao;
72 
74  {
75  $this->clearingDao = $clearingDao;
76  $this->uploadDao = $uploadDao;
77  $this->agentDao = $agentDao;
78  $this->dbManager = $dbManager;
79  $this->decisionTypes = new DecisionTypes();
80  $this->clearingDecisionFilter = $clearingDecisionFilter;
81  $this->treeDao = $treeDao;
82  }
83 
84  public function run($uploadId, $userId=2, $groupId=2, $jobId=1, $args="")
85  {
86  $GLOBALS['userId'] = $userId;
87  $GLOBALS['jobId'] = $jobId;
88  $GLOBALS['groupId'] = $groupId;
89 
90  /* these appear not to be used by the reuser: mock them to something wrong
91  */
92  $this->clearingEventProcessor = M::mock(LicenseRef::class);
93  $this->decisionTypes = M::mock(LicenseRef::class);
94  $this->agentLicenseEventProcessor = M::mock(LicenseRef::class);
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('decision.types')->andReturn($this->decisionTypes);
102  $container->shouldReceive('get')->with('businessrules.clearing_event_processor')->andReturn($this->clearingEventProcessor);
103  $container->shouldReceive('get')->with('businessrules.clearing_decision_filter')->andReturn($this->clearingDecisionFilter);
104  $container->shouldReceive('get')->with('businessrules.clearing_decision_processor')->andReturn($this->clearingDecisionProcessor);
105  $container->shouldReceive('get')->with('businessrules.agent_license_event_processor')->andReturn($this->agentLicenseEventProcessor);
106  $container->shouldReceive('get')->with('dao.tree')->andReturn($this->treeDao);
107  $GLOBALS['container'] = $container;
108 
109  $fgetsMock = M::mock(\Fossology\Lib\Agent\FgetsMock::class);
110  $fgetsMock->shouldReceive("fgets")->with(STDIN)->andReturn($uploadId, false);
111  $GLOBALS['fgetsMock'] = $fgetsMock;
112 
113  $exitval = 0;
114 
115  ob_start();
116 
117  include(dirname(dirname(__DIR__)).'/agent/reuser.php');
118 
119  $output = ob_get_clean();
120 
121  return array(true, $output, $exitval);
122  }
123 }
Structure of an Agent with all required parameters.
Definition: Agent.php:51
Various utility functions to filter ClearingDecision.
run($uploadId, $userId=2, $groupId=2, $jobId=1, $args="")
Function to run agent from scheduler.
Namespace used by reuser agent.
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:28
Namespace to hold test cases for Reuser agent.