5 require_once(CONST_BasePath.'/lib/Shell.php');
 
   7 class ShellTest extends \PHPUnit\Framework\TestCase
 
   9     public function testNew()
 
  11         $this->expectException('ArgumentCountError');
 
  12         $this->expectExceptionMessage('Too few arguments to function');
 
  13         $oCmd = new \Nominatim\Shell();
 
  16         $oCmd = new \Nominatim\Shell('wc', '-l', 'file.txt');
 
  23     public function testaddParams()
 
  25         $oCmd = new \Nominatim\Shell('grep');
 
  26         $oCmd->addParams('-a', 'abc')
 
  32             'no escaping needed, chained'
 
  35         $oCmd = new \Nominatim\Shell('grep');
 
  37         $oCmd->addParams(null);
 
  40         $this->assertEmpty($oCmd->aParams);
 
  41         $this->assertSame('grep', $oCmd->escapedCmd(), 'empty params');
 
  43         $oCmd = new \Nominatim\Shell('echo', '-n', 0);
 
  50         $oCmd = new \Nominatim\Shell('/path with space/do.php');
 
  51         $oCmd->addParams('-a', ' b ');
 
  52         $oCmd->addParams('--flag');
 
  53         $oCmd->addParams('two words');
 
  54         $oCmd->addParams('v=1');
 
  57             "'/path with space/do.php' -a ' b ' --flag 'two words' 'v=1'",
 
  62         $oCmd = new \Nominatim\Shell('grep');
 
  63         $oCmd->addParams(';', '|more&', '2>&1');
 
  66             "grep ';' '|more&' '2>&1'",
 
  68             'escape shell characters'
 
  72     public function testaddEnvPair()
 
  74         $oCmd = new \Nominatim\Shell('date');
 
  76         $oCmd->addEnvPair('one', 'two words')
 
  77              ->addEnvPair('null', null)
 
  78              ->addEnvPair(null, 'null')
 
  79              ->addEnvPair('empty', '')
 
  80              ->addEnvPair('', 'empty');
 
  83             array('one' => 'two words', 'empty' => ''),
 
  87         $oCmd->addEnvPair('one', 'overwrite');
 
  89             array('one' => 'overwrite', 'empty' => ''),
 
  94     public function testClone()
 
  96         $oCmd = new \Nominatim\Shell('wc', '-l', 'file.txt');
 
  98         $oCmd->addParams('--flag');
 
  99         $oCmd2->addParams('--flag2');
 
 102             "wc -l 'file.txt' --flag",
 
 107             "wc -l 'file.txt' --flag2",
 
 112     public function testRun()
 
 114         $oCmd = new \Nominatim\Shell('echo');
 
 116         $this->assertSame(0, $oCmd->run());
 
 118         // var_dump($sStdout);