FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
SchedulerTestRunnerCli.php
1 <?php
2 /*
3 Copyright (C) 2019, 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\Ojo\Test;
20 
22 
23 include_once(__DIR__.'/../../../lib/php/Test/Agent/AgentTestMockHelper.php');
24 
30 {
34  private $testDb;
35 
36  public function __construct(TestPgDb $testDb)
37  {
38  $this->testDb = $testDb;
39  }
40 
41  public function run($args)
42  {
43  $sysConf = $this->testDb->getFossSysConf();
44 
45  $agentName = "ojo";
46 
47  $agentDir = dirname(dirname(__DIR__));
48  $execDir = "$agentDir/agent";
49  system("install -D $agentDir/VERSION $sysConf/mods-enabled/$agentName/VERSION");
50 
51  $pipeFd = popen($cmd = "$execDir/$agentName $args", "r");
52  $success = $pipeFd !== false;
53 
54  $output = "";
55  $retCode = -1;
56  if ($success) {
57  while (($buffer = fgets($pipeFd, 4096)) !== false) {
58  $output .= $buffer;
59  }
60  $retCode = pclose($pipeFd);
61  } else {
62  print "failed opening pipe to $cmd";
63  }
64 
65  unlink("$sysConf/mods-enabled/$agentName/VERSION");
66  rmdir("$sysConf/mods-enabled/$agentName");
67  rmdir("$sysConf/mods-enabled");
68 
69  return array($success, $output, $retCode);
70  }
71 }