Laravel 5.2 -Phpunit-如果测试失败,如何将电子邮件发送给支持团队



我想知道,如果我的一个Unitest失败了,我如何将电子邮件发送给支持团队?

<?php
use IlluminateFoundationTestingWithoutMiddleware;
use IlluminateFoundationTestingDatabaseMigrations;
use IlluminateFoundationTestingDatabaseTransactions;
class ExampleTest extends TestCase
{
    public function testBasicExample()
    {
         $this->visit('/login')->see('Hello');
    }
}

如果该测试失败了,我如何发送电子邮件?

您应该将phpunit命令包装在另一个脚本中,如果返回代码不是0。

实际上,您可以创建一个自定义工匠命令,该命令将运行phpunit,采用输出并使用Mail立面发送报告。Afaik phpunit没有此功能开箱即用

编辑代码示例:

public function handle()
{
    $command = new Process("vendor/bin/phpunit");
    $command->run();
    $this->info($command->getIncrementalOutput());
    if($command->isSuccessful()) {
      // do your stuff    
    }
    // do other stuff
}

最新更新