Fixed test to mock form properly
This commit is contained in:
parent
c200693b05
commit
e6cdaa5a1a
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace tests\codeception\unit\models;
|
namespace tests\codeception\unit\models;
|
||||||
|
|
||||||
|
use app\models\ContactForm;
|
||||||
use Yii;
|
use Yii;
|
||||||
use yii\codeception\TestCase;
|
use yii\codeception\TestCase;
|
||||||
use Codeception\Specify;
|
use Codeception\Specify;
|
||||||
@ -26,7 +27,10 @@ class ContactFormTest extends TestCase
|
|||||||
|
|
||||||
public function testContact()
|
public function testContact()
|
||||||
{
|
{
|
||||||
$model = $this->createMock('app\models\ContactForm', ['validate']);
|
/** @var ContactForm $model */
|
||||||
|
$model = $this->getMockBuilder('app\models\ContactForm')
|
||||||
|
->setMethods(['validate'])
|
||||||
|
->getMock();
|
||||||
$model->expects($this->once())->method('validate')->will($this->returnValue(true));
|
$model->expects($this->once())->method('validate')->will($this->returnValue(true));
|
||||||
|
|
||||||
$model->attributes = [
|
$model->attributes = [
|
||||||
@ -36,9 +40,8 @@ class ContactFormTest extends TestCase
|
|||||||
'body' => 'body of current message',
|
'body' => 'body of current message',
|
||||||
];
|
];
|
||||||
|
|
||||||
$model->contact('admin@example.com');
|
$this->specify('email should be send', function () use ($model) {
|
||||||
|
expect('ContactForm::contact() should return true', $model->contact('admin@example.com'))->true();
|
||||||
$this->specify('email should be send', function () {
|
|
||||||
expect('email file should exist', file_exists($this->getMessageFile()))->true();
|
expect('email file should exist', file_exists($this->getMessageFile()))->true();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user