Есть простая форма:
Код: Выделить всё
<?php
namespace frontend\forms;
use yii\base\Model;
class ContactForm extends Model
{
public $name;
public $email;
public $body;
public $verifyCode;
/**
* {@inheritdoc}
*/
public function rules()
{
return [
['name', 'required'],
['body', 'required'],
['email', 'required'],
['email', 'email'],
['verifyCode', 'captcha'],
];
}
/**
* @return array
*/
public function attributeLabels()
{
return [
'verifyCode' => 'Verification Code',
];
}
}
Код: Выделить всё
<?php
namespace frontend\tests\unit\forms;
use frontend\forms\ContactForm;
class ContactFormTest extends \Codeception\Test\Unit
{
public function testCorrectForm()
{
$form = new ContactForm();
$form->name = 'Tester';
$form->email = '[email protected]';
$form->body = 'body of current message';
expect_that($form->validate());
}
}
Failed asserting that a boolean is not empty.
Форма не проходит валидацию. Если в правилах капчи указать 'skipOnEmpty' => true, то тест проходит успешно. Но как-то мне этот способ не очень нравится.