FOSSology  4.4.0
Open Source License Compliance by Open Source Software
SchedulerTestRunnerCli.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2015 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 namespace Fossology\SpdxTwo\Test;
9 
11 
12 include_once(__DIR__.'/../../../lib/php/Test/Agent/AgentTestMockHelper.php');
13 include_once(__DIR__.'/SchedulerTestRunner.php');
14 
20 {
24  private $testDb;
25 
26  public function __construct(TestPgDb $testDb)
27  {
28  $this->testDb = $testDb;
29  }
30 
31  public function run($uploadId, $userId=2, $groupId=2, $jobId=1, $args="")
32  {
33  $sysConf = $this->testDb->getFossSysConf();
34 
35  $agentName = "spdx2";
36 
37  $agentDir = dirname(dirname(__DIR__));
38  $execDir = "$agentDir/agent";
39 
40  $pipeFd = popen($cmd = "echo $uploadId | $execDir/$agentName --userID=$userId "
41  . "--groupID=$groupId --jobId=$jobId --scheduler_start -c $sysConf $args", "r");
42  $success = $pipeFd !== false;
43 
44  $output = "";
45  $retCode = -1;
46  if ($success) {
47  while (($buffer = fgets($pipeFd, 4096)) !== false) {
48  $output .= $buffer;
49  }
50  $retCode = pclose($pipeFd);
51  } else {
52  print "failed opening pipe to $cmd";
53  }
54 
55  return array($success, $output, $retCode);
56  }
57 }
run($uploadId, $userId=2, $groupId=2, $jobId=1, $args="")
Function to run agent from scheduler.
Namespace to hold test cases for SPDX2 agent.