Do not mock contact form in test

This commit is contained in:
Alexander Makarov 2020-11-16 16:22:10 +03:00
parent 7959d142a7
commit a56693d88f
No known key found for this signature in database
GPG Key ID: 3617B79C6A325E4A

View File

@ -7,7 +7,6 @@ use yii\mail\MessageInterface;
class ContactFormTest extends \Codeception\Test\Unit
{
private $model;
/**
* @var \UnitTester
*/
@ -15,23 +14,17 @@ class ContactFormTest extends \Codeception\Test\Unit
public function testEmailIsSentOnContact()
{
/** @var ContactForm $model */
$this->model = $this->getMockBuilder('app\models\ContactForm')
->setMethods(['validate'])
->getMock();
$model = new ContactForm();
$this->model->expects($this->once())
->method('validate')
->willReturn(true);
$this->model->attributes = [
$model->attributes = [
'name' => 'Tester',
'email' => 'tester@example.com',
'subject' => 'very important letter subject',
'body' => 'body of current message',
'verifyCode' => 'testme',
];
expect_that($this->model->contact('admin@example.com'));
expect_that($model->contact('admin@example.com'));
// using Yii2 module actions to check email was sent
$this->tester->seeEmailIsSent();