duandange7480 2016-08-10 15:21
浏览 76
已采纳

如何断言结果是PHPUnit中的电子邮件?

I would like to be able to test that a result is an email (myMail@provider.com ..)

I have tried to test if it's string using this :

$this->assertInternalType('string', $myExpectedEmail);

But I think it's not very accurate ... I tried this :

$this->assertInternalType('email', $myExpectedEmail);

But I get this error:

Type specified for PHPUnit_Framework_Constraint_IsType <email> is not a valid type.

Any idea/best practice of how to test email format in PHPunit ?

  • 写回答

2条回答 默认 最新

  • doulou0882 2016-08-10 16:11
    关注

    You could use a regular expression for validate an email address. Something like:

        $this->assertRegExp('/^.+\@\S+\.\S+$/', $myExpectedEmail);
    

    hope this help

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?