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 
8 namespace Fossology\Reuser\Test;
9 
20 use Mockery as M;
21 
22 include_once(__DIR__.'/../../../lib/php/Test/Agent/AgentTestMockHelper.php');
23 include_once(__DIR__.'/SchedulerTestRunner.php');
24 
25 include(dirname(dirname(__DIR__)).'/agent/ReuserAgent.php');
26 
32 {
36  private $dbManager;
37 
41  private $clearingDao;
45  private $copyrightDao;
57  private $uploadDao;
61  private $agentDao;
65  private $treeDao;
66 
70  {
71  $this->clearingDao = $clearingDao;
72  $this->copyrightDao = $copyrightDao;
73  $this->uploadDao = $uploadDao;
74  $this->agentDao = $agentDao;
75  $this->dbManager = $dbManager;
76  $this->decisionTypes = new DecisionTypes();
77  $this->clearingDecisionFilter = $clearingDecisionFilter;
78  $this->treeDao = $treeDao;
79  }
80 
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  /* these appear not to be used by the reuser: mock them to something wrong
88  */
89  $this->clearingEventProcessor = M::mock(LicenseRef::class);
90  $this->decisionTypes = M::mock(LicenseRef::class);
91  $this->agentLicenseEventProcessor = M::mock(LicenseRef::class);
92 
93  $container = M::mock('Container');
94  $container->shouldReceive('get')->with('db.manager')->andReturn($this->dbManager);
95  $container->shouldReceive('get')->with('dao.agent')->andReturn($this->agentDao);
96  $container->shouldReceive('get')->with('dao.clearing')->andReturn($this->clearingDao);
97  $container->shouldReceive('get')->with('dao.copyright')->andReturn($this->copyrightDao);
98  $container->shouldReceive('get')->with('dao.upload')->andReturn($this->uploadDao);
99  $container->shouldReceive('get')->with('decision.types')->andReturn($this->decisionTypes);
100  $container->shouldReceive('get')->with('businessrules.clearing_event_processor')->andReturn($this->clearingEventProcessor);
101  $container->shouldReceive('get')->with('businessrules.clearing_decision_filter')->andReturn($this->clearingDecisionFilter);
102  $container->shouldReceive('get')->with('businessrules.clearing_decision_processor')->andReturn($this->clearingDecisionProcessor);
103  $container->shouldReceive('get')->with('businessrules.agent_license_event_processor')->andReturn($this->agentLicenseEventProcessor);
104  $container->shouldReceive('get')->with('dao.tree')->andReturn($this->treeDao);
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/reuser.php');
116 
117  $output = ob_get_clean();
118 
119  return array(true, $output, $exitval);
120  }
121 }
Structure of an Agent with all required parameters.
Definition: Agent.php:41
Various utility functions to filter ClearingDecision.
Utility functions to process ClearingDecision.
run($uploadId, $userId=2, $groupId=2, $jobId=1, $args="")
Function to run agent from scheduler.
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:16
Namespace to hold test cases for Reuser agent.