【问题标题】:Laravel 5.2 - PHPunit - How to send email to support team if test has failed?Laravel 5.2 - PHPunit - 如果测试失败,如何向支持团队发送电子邮件?
【发布时间】:2019-10-09 15:55:53
【问题描述】:

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

<?php

use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class ExampleTest extends TestCase
{
    public function testBasicExample()
    {
         $this->visit('/login')->see('Hello');
    }
}

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

【问题讨论】:

    标签: laravel unit-testing laravel-5 phpunit


    【解决方案1】:

    您应该将您的phpunit 命令包装在另一个脚本中,如果返回码不为 0,该脚本将发送 PHP 单元的报告。

    实际上,您可以创建一个自定义工匠命令,该命令将运行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
    }
    

    【讨论】:

      猜你喜欢
      • 2022-11-23
      • 2012-11-10
      • 2022-08-20
      • 1970-01-01
      • 2016-08-20
      • 2019-03-09
      • 1970-01-01
      • 2016-10-29
      • 2022-08-13
      相关资源
      最近更新 更多