FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
SchedulerTestRunnerCli.php
1 <?php
2 /*
3 Copyright (C) 2015, 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\SpdxTwo\Test;
20 
22 
23 include_once(__DIR__.'/../../../lib/php/Test/Agent/AgentTestMockHelper.php');
24 include_once(__DIR__.'/SchedulerTestRunner.php');
25 
31 {
35  private $testDb;
36 
37  public function __construct(TestPgDb $testDb)
38  {
39  $this->testDb = $testDb;
40  }
41 
42  public function run($uploadId, $userId=2, $groupId=2, $jobId=1, $args="")
43  {
44  $sysConf = $this->testDb->getFossSysConf();
45 
46  $agentName = "spdx2";
47 
48  $agentDir = dirname(dirname(__DIR__));
49  $execDir = "$agentDir/agent";
50 
51  $pipeFd = popen($cmd = "echo $uploadId | $execDir/$agentName --userID=$userId "
52  . "--groupID=$groupId --jobId=$jobId --scheduler_start -c $sysConf $args", "r");
53  $success = $pipeFd !== false;
54 
55  $output = "";
56  $retCode = -1;
57  if ($success) {
58  while (($buffer = fgets($pipeFd, 4096)) !== false) {
59  $output .= $buffer;
60  }
61  $retCode = pclose($pipeFd);
62  } else {
63  print "failed opening pipe to $cmd";
64  }
65 
66  return array($success, $output, $retCode);
67  }
68 }
run($uploadId, $userId=2, $groupId=2, $jobId=1, $args="")
Function to run agent from scheduler.
Namespace to hold test cases for SPDX2 agent.