2013-12-12 15:37:47 +01:00
|
|
|
<?php
|
|
|
|
|
2015-03-03 17:18:17 +01:00
|
|
|
/**
|
|
|
|
* PHPCI - Continuous Integration for PHP
|
|
|
|
*
|
|
|
|
* @copyright Copyright 2015, Block 8 Limited.
|
|
|
|
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
|
|
|
* @link https://www.phptesting.org/
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Tests\PHPCI\Plugin\Helper;
|
2013-12-12 15:37:47 +01:00
|
|
|
|
2014-05-11 19:43:41 +02:00
|
|
|
use PHPCI\Helper\UnixCommandExecutor;
|
2013-12-12 15:37:47 +01:00
|
|
|
|
2015-03-03 17:18:17 +01:00
|
|
|
class CommandExecutorTest extends \PHPUnit_Framework_TestCase
|
2013-12-12 15:37:47 +01:00
|
|
|
{
|
|
|
|
/**
|
2014-05-11 19:44:13 +02:00
|
|
|
* @var UnixCommandExecutor
|
2013-12-12 15:37:47 +01:00
|
|
|
*/
|
|
|
|
protected $testedExecutor;
|
|
|
|
|
|
|
|
protected function setUp()
|
|
|
|
{
|
2015-03-03 17:18:17 +01:00
|
|
|
if (IS_WIN) {
|
|
|
|
$this->markTestSkipped("Cannot test UnixCommandExecutor on ".PHP_OS);
|
|
|
|
return;
|
|
|
|
}
|
2013-12-12 15:37:47 +01:00
|
|
|
parent::setUp();
|
2013-12-13 17:10:54 +01:00
|
|
|
$mockBuildLogger = $this->prophesize('PHPCI\Logging\BuildLogger');
|
2014-05-11 19:43:41 +02:00
|
|
|
$this->testedExecutor = new UnixCommandExecutor($mockBuildLogger->reveal(), __DIR__ . "/");
|
2013-12-12 15:37:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetLastOutput_ReturnsOutputOfCommand()
|
|
|
|
{
|
2014-05-09 09:25:24 +02:00
|
|
|
$this->testedExecutor->executeCommand(array('echo "%s"', 'Hello World'));
|
2013-12-12 15:37:47 +01:00
|
|
|
$output = $this->testedExecutor->getLastOutput();
|
|
|
|
$this->assertEquals("Hello World", $output);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetLastOutput_ForgetsPreviousCommandOutput()
|
|
|
|
{
|
2014-05-09 09:25:24 +02:00
|
|
|
$this->testedExecutor->executeCommand(array('echo "%s"', 'Hello World'));
|
|
|
|
$this->testedExecutor->executeCommand(array('echo "%s"', 'Hello Tester'));
|
2013-12-12 15:37:47 +01:00
|
|
|
$output = $this->testedExecutor->getLastOutput();
|
|
|
|
$this->assertEquals("Hello Tester", $output);
|
|
|
|
}
|
2013-12-12 17:04:07 +01:00
|
|
|
|
|
|
|
public function testExecuteCommand_ReturnsTrueForValidCommands()
|
|
|
|
{
|
2014-05-09 09:25:24 +02:00
|
|
|
$returnValue = $this->testedExecutor->executeCommand(array('echo "%s"', 'Hello World'));
|
2013-12-12 17:04:07 +01:00
|
|
|
$this->assertTrue($returnValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testExecuteCommand_ReturnsFalseForInvalidCommands()
|
|
|
|
{
|
2014-05-09 09:25:24 +02:00
|
|
|
$returnValue = $this->testedExecutor->executeCommand(array('eerfdcvcho "%s" > /dev/null 2>&1', 'Hello World'));
|
2013-12-12 17:04:07 +01:00
|
|
|
$this->assertFalse($returnValue);
|
|
|
|
}
|
2013-12-12 17:17:11 +01:00
|
|
|
|
|
|
|
public function testFindBinary_ReturnsPathInSpecifiedRoot()
|
|
|
|
{
|
|
|
|
$thisFileName = "CommandExecutorTest.php";
|
|
|
|
$returnValue = $this->testedExecutor->findBinary($thisFileName);
|
|
|
|
$this->assertEquals(__DIR__ . "/" . $thisFileName, $returnValue);
|
|
|
|
}
|
2015-03-03 17:18:17 +01:00
|
|
|
}
|