at the end of the day, it was inevitable

This commit is contained in:
Mo Elzubeir
2022-12-09 08:36:26 -06:00
commit 1218570914
1768 changed files with 887087 additions and 0 deletions
+85
View File
@@ -0,0 +1,85 @@
<?php
namespace Command\Util;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\BufferedOutput;
/**
* Class CommandTest
* @package Command\Util
*/
class CommandTest
{
/**
* @var Application
*/
private $application;
/**
* @var InputInterface
*/
private $input;
/**
* @var BufferedOutput
*/
private $output;
/**
* @var integer
*/
private $exitCode;
/**
* Command constructor.
*
* @param Application $application A Application instance.
* @param string $command Command name.
* @param array $params Command parameters.
*/
public function __construct(
Application $application,
$command,
array $params = []
) {
$this->application = $application;
$this->input = new ArrayInput([ 'command' => $command ] + $params);
}
/**
* Run this command.
*
* @return CommandTest
*/
public function run()
{
$this->output = new BufferedOutput();
$this->exitCode = $this->application->run($this->input, $this->output);
return $this;
}
/**
* Get exit code.
*
* @return integer
*/
public function getExitCode()
{
return $this->exitCode;
}
/**
* Get output.
*
* @return string
*/
public function getOutput()
{
return $this->output->fetch();
}
}
+45
View File
@@ -0,0 +1,45 @@
<?php
namespace Command\Util;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\HttpKernel\KernelInterface;
/**
* Class CommandTestFactory
* @package Command\Util
*/
class CommandTestFactory
{
/**
* @var Application
*/
private $application;
/**
* CommandRunner constructor.
*
* @param KernelInterface $kernel A KernelInterface instance.
*/
public function __construct(KernelInterface $kernel)
{
$this->application = new Application($kernel);
// If don't set to false, application will call 'exit' after command was
// executed.
$this->application->setAutoExit(false);
}
/**
* Create new command instance.
*
* @param string $command Command name.
* @param array $params Command parameters.
*
* @return CommandTest
*/
public function create($command, array $params = [])
{
return new CommandTest($this->application, $command, $params);
}
}