magallanes/tests/Runtime/RuntimeMockup.php

82 lines
1.8 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 = [];
protected $ranCommandTimeouts = [];
2017-01-08 05:11:19 +01:00
protected $forceFail = [];
2017-01-01 05:28:58 +01:00
public function getRanCommands()
{
return $this->ranCommands;
}
public function getRanCommandTimeoutFor($cmd)
{
return isset($this->ranCommandTimeouts[$cmd]) ? $this->ranCommandTimeouts[$cmd] : null;
}
2017-01-01 05:28:58 +01:00
/**
* Generate the Release ID
*/
2022-04-10 06:20:03 +02:00
public function generateReleaseId(): Runtime
2017-01-01 05:28:58 +01:00
{
$this->setReleaseId('1234567890');
return $this;
}
/**
* Execute a command locally
*/
2022-04-10 06:20:03 +02:00
public function runLocalCommand(string $cmd, int $timeout = 120): Process
2017-01-01 05:28:58 +01:00
{
$this->ranCommands[] = $cmd;
$this->ranCommandTimeouts[$cmd] = $timeout;
2017-01-01 05:28:58 +01:00
$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
*/
2022-04-10 06:20:03 +02:00
public function getTempFile(): string
2017-01-01 05:28:58 +01:00
{
return '/tmp/mageXYZ';
}
2017-01-05 01:46:40 +01:00
/**
* Allows to set an invalid environments
*
* @param string $environment
* @return Runtime
*/
2022-04-10 06:20:03 +02:00
public function setInvalidEnvironment($environment): Runtime
2017-01-05 01:46:40 +01:00
{
$this->environment = $environment;
return $this;
}
2017-01-08 05:11:19 +01:00
2022-04-10 06:20:03 +02:00
public function forceFail($cmd): void
2017-01-08 05:11:19 +01:00
{
$this->forceFail[] = $cmd;
}
2017-01-01 05:34:14 +01:00
}