Написан тест для поведения beforeSave модели EmailActivation

This commit is contained in:
ErickSkrauch
2016-07-27 01:58:06 +03:00
parent c25bfeb8bc
commit ed6bc672cb
2 changed files with 40 additions and 6 deletions

View File

@ -28,4 +28,30 @@ class EmailActivationTest extends DbTestCase {
});
}
public function testBeforeSave() {
$this->specify('method should generate value for key field if it empty', function() {
$model = new EmailActivation();
$model->beforeSave(true);
expect($model->key)->notNull();
});
$this->specify('method should repeat code generation if code duplicate with exists', function() {
/** @var EmailActivation|\PHPUnit_Framework_MockObject_MockObject $model */
$model = $this->getMockBuilder(EmailActivation::class)
->setMethods(['generateKey', 'isKeyExists'])
->getMock();
$model->expects($this->exactly(3))
->method('generateKey')
->will($this->onConsecutiveCalls('1', '2', '3'));
$model->expects($this->exactly(3))
->method('isKeyExists')
->will($this->onConsecutiveCalls(true, true, false));
$model->beforeSave(true);
expect($model->key)->equals('3');
});
}
}