Php 如何测试依赖于日期的Symfony命令?

Php 如何测试依赖于日期的Symfony命令?,php,symfony,testing,behat,Php,Symfony,Testing,Behat,我运行了一个CLI Symfony命令,该命令可用于上个月的事务。这是CLI-我不能只是模拟系统时钟,那么如何用Behat测试它?现在是11月,以下场景将在12月失败: Scenario: Do something with last month transactions Given there is a transaction "7ccf7387" for 2020-10 And there is a transaction "39d7f278

我运行了一个CLI Symfony命令,该命令可用于上个月的事务。这是CLI-我不能只是模拟系统时钟,那么如何用Behat测试它?现在是11月,以下场景将在12月失败:

  Scenario: Do something with last month transactions
    Given there is a transaction "7ccf7387" for 2020-10
    And there is a transaction "39d7f278" for 2020-10
    When I execute "bin/console billing:last-month" from project root
    Then command should succeed
    And output should contain "Closed 2 transactions"
这是当前的命令实现:

final class closelastmount extends命令
{
/* ... */
受保护的函数执行(InputInterface$input,OutputInterface$output):int
{
$month=(GregorianCalendar::UTC())->currentMonth()->previous();
$trxs=$this->bus->dispatch(新的GetActiveTrxsByMonthQuery($month));
foreach($trx作为$trx){
$this->bus->dispatch(新建CloseTransactionCommand($trx->id));
}
$this->io->success(sprintf('Closed%d个事务),count($trx));
返回0;
}
/* ... */
}
我可以强制用户在命令参数中始终传递当前月份,但这并不雅观。总是返回当前月份的新Symfony服务是一种过度使用。

更好:

这样,您可以简单地执行以下操作:

上个月有一笔交易“7ccf7387”
上个月有一笔交易“39d7f278”

为什么这在12月不起作用?@Nico因为场景中的日期是10月。啊,我真傻。。。。。那么,为什么不动态插入装置(这样它们总是在最后一个月根据执行情况插入,而不是在2020年10月固定)?
/**
 * @Given /^There is a transaction "([^"]*)" for last month$/
 */
public function thereIsATransaction(string $transactionId) {}