Я хочу выполнить модульное тестирование команды как есть, но модульный тест не дает результатов.< /p>
Это моя тестовая установка:
Код: Выделить всё
class TimrOverviewCommandTest extends TestCase
{
public function testTimrOverviewCommand()
{
$input = new ArgvInput(argv: [
"overview",
"--csv",
"tests/csv/day_report.csv"
]);
$buffered = new BufferedOutput();
$app = new Timr(__DIR__);
$exitCode = $app->run($input, $buffered);
$result = $buffered->fetch();
$this::assertSame(actual: $result, expected: "2024-10-18: Expected 5 / Delivered 5.25\n");
}
}
Код: Выделить всё
class Timr
{
private readonly Application $app;
public function __construct(string $rootDir)
{
$parser = new CsvParser($rootDir);
$app = new Application('timr', '1.0.0');
$app->add(new TimrReportCommand($parser));
$app->add(new TimrOverviewCommand($parser));
$this->app = $app;
}
public function run(?InputInterface $input = null, ?OutputInterface $output = null): int
{
return $this->app->run($input, $output);
}
}
- команда тестирования Symfony с phpunit
- Symfony — консольные команды недоступны при запуске модульных тестов
Подробнее здесь: https://stackoverflow.com/questions/791 ... on-command