shlink/module/CLI/test/CliTestUtilsTrait.php

47 lines
1.3 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
2021-12-16 23:46:52 +03:00
use Symfony\Component\Console\Input\InputDefinition;
2021-04-08 14:34:14 +03:00
use Symfony\Component\Console\Tester\CommandTester;
trait CliTestUtilsTrait
{
use ProphecyTrait;
/**
* @return ObjectProphecy|Command
*/
private function createCommandMock(string $name): ObjectProphecy
{
$command = $this->prophesize(Command::class);
$command->getName()->willReturn($name);
$command->getDefinition()->willReturn($name);
$command->isEnabled()->willReturn(true);
$command->getAliases()->willReturn([]);
2021-12-16 23:46:52 +03:00
$command->getDefinition()->willReturn(new InputDefinition());
$command->setApplication(Argument::type(Application::class))->willReturn(function (): void {
});
return $command;
}
2021-04-08 14:34:14 +03:00
private function testerForCommand(Command $mainCommand, Command ...$extraCommands): CommandTester
{
$app = new Application();
$app->add($mainCommand);
foreach ($extraCommands as $command) {
$app->add($command);
}
return new CommandTester($mainCommand);
}
}