Files

48 lines
1.4 KiB
PHP
Raw Permalink Normal View History

<?php
declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Util;
2023-08-19 11:48:04 +02:00
use PHPUnit\Framework\MockObject\Generator\Generator;
use PHPUnit\Framework\MockObject\Stub;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
2021-12-16 21:46:52 +01:00
use Symfony\Component\Console\Input\InputDefinition;
2021-04-08 13:34:14 +02:00
use Symfony\Component\Console\Tester\CommandTester;
class CliTestUtils
{
public static function createCommandStub(string $name): Stub&Command
{
static $generator = null;
if ($generator === null) {
$generator = new Generator();
}
2023-10-07 10:56:04 +02:00
$command = $generator->testDouble(
Command::class,
mockObject: false,
callOriginalConstructor: false,
callOriginalClone: false,
);
$command->method('getName')->willReturn($name);
$command->method('isEnabled')->willReturn(true);
$command->method('getAliases')->willReturn([]);
$command->method('getDefinition')->willReturn(new InputDefinition());
return $command;
}
2021-04-08 13:34:14 +02:00
public static function testerForCommand(Command $mainCommand, Command ...$extraCommands): CommandTester
2021-04-08 13:34:14 +02:00
{
$app = new Application();
2025-12-02 12:11:56 +01:00
$app->addCommand($mainCommand);
2021-04-08 13:34:14 +02:00
foreach ($extraCommands as $command) {
2025-12-02 12:11:56 +01:00
$app->addCommand($command);
2021-04-08 13:34:14 +02:00
}
return new CommandTester($mainCommand);
}
}