magallanes/tests/Runtime/RuntimeMockup.php

83 lines
1.6 KiB
PHP
Raw Normal View History

2017-01-01 05:28:58 +01:00
<?php
2017-01-01 22:20:43 +01:00
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
2017-01-01 05:28:58 +01:00
namespace Mage\Tests\Runtime;
use Mage\Runtime\Runtime;
use Symfony\Component\Process\Process;
class RuntimeMockup extends Runtime
{
protected $ranCommands = [];
2017-01-08 05:11:19 +01:00
protected $forceFail = [];
2017-01-01 05:28:58 +01:00
public function getRanCommands()
{
return $this->ranCommands;
}
/**
* Generate the Release ID
*
2017-01-01 05:33:34 +01:00
* @return Runtime
2017-01-01 05:28:58 +01:00
*/
public function generateReleaseId()
{
$this->setReleaseId('1234567890');
return $this;
}
/**
* Execute a command locally
*
* @param string $cmd Command to execute
* @param int $timeout Seconds to wait
* @return Process
*/
public function runLocalCommand($cmd, $timeout = 120)
{
$this->ranCommands[] = $cmd;
$process = new ProcessMockup($cmd);
2017-01-08 05:11:19 +01:00
$process->forceFail = $this->forceFail;
2017-01-01 05:28:58 +01:00
$process->setTimeout($timeout);
$process->run();
return $process;
}
/**
* Gets a Temporal File name
*
* @return string
*/
public function getTempFile()
{
return '/tmp/mageXYZ';
}
2017-01-05 01:46:40 +01:00
/**
* Allows to set an invalid environments
*
* @param string $environment
* @return Runtime
*/
public function setInvalidEnvironment($environment)
{
$this->environment = $environment;
return $this;
}
2017-01-08 05:11:19 +01:00
public function forceFail($cmd)
{
$this->forceFail[] = $cmd;
}
2017-01-01 05:34:14 +01:00
}