【问题标题】:Laravel Console Test with unpredictable output输出不可预测的 Laravel 控制台测试
【发布时间】:2020-08-03 15:48:51
【问题描述】:

是否可以用不可预测的输出测试 Laravel Artisan Command?

例如,我的 artisan 命令有一个输出:

Your new password is: bGiJjIjAT0

那个bGiJjIjAT0实际上是一个随机字符串。 artisan 命令生成随机字符串。

AFAIK,控制台测试 expectsOutput 需要精确的字符串。

【问题讨论】:

    标签: laravel testing console tdd laravel-artisan


    【解决方案1】:

    试试这个:

        Artisan::call('your:command');
        $output = Artisan::output();
        $this->assertStringContainsString('Your new password is: ', $output);
    

    【讨论】:

      猜你喜欢
      • 2018-08-27
      • 2017-10-31
      • 1970-01-01
      • 1970-01-01
      • 2019-07-23
      • 2013-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多