测试命令在终端中有效,但在 php 中无效

Posted

技术标签:

【中文标题】测试命令在终端中有效,但在 php 中无效【英文标题】:test comman works in terminal but not in php 【发布时间】:2021-10-11 05:22:10 【问题描述】:

当我在终端中执行php artisan test --testsuite=myTestsuite 时,我得到了正确的结果,这就是这个测试套件执行的测试。

但是当我执行php artisan myCommand 时:

然后首先执行 phpunit.xml 中列出的测试套件,然后执行我传递名称的测试套件。

有人知道为什么会这样吗?

【问题讨论】:

请不要发布代码图片,而是将代码添加到代码块中。 【参考方案1】:

要在命令中调用工匠,您需要使用下一个构造:

$this->call('test', ['test suite' => 'MyTestsuite']);

【讨论】:

【参考方案2】:

解决了

shell_exec('php artisan test --testsuite=MyTestsuite')

如果有人找到其他解决方案,请告诉我。谢谢

【讨论】:

【参考方案3】:

您可以使用Artisan 外观,如下所示:

    Artisan::call('test --testsuite=myTestsuite'); 
    $output = Artisan::output();

【讨论】:

以上是关于测试命令在终端中有效,但在 php 中无效的主要内容,如果未能解决你的问题,请参考以下文章