basic application template tests adjusted

This commit is contained in:
Mark 2014-06-09 16:10:16 +04:00
parent 2dedb6aa2c
commit 7a467ed501
2 changed files with 18 additions and 22 deletions

View File

@ -4,10 +4,11 @@ namespace tests\unit\models;
use Yii; use Yii;
use yii\codeception\TestCase; use yii\codeception\TestCase;
use Codeception\Specify;
class ContactFormTest extends TestCase class ContactFormTest extends TestCase
{ {
use \Codeception\Specify; use Specify;
protected function setUp() protected function setUp()
{ {
@ -55,4 +56,5 @@ class ContactFormTest extends TestCase
{ {
return Yii::getAlias(Yii::$app->mail->fileTransportPath) . '/testing_message.eml'; return Yii::getAlias(Yii::$app->mail->fileTransportPath) . '/testing_message.eml';
} }
} }

View File

@ -4,11 +4,12 @@ namespace tests\unit\models;
use Yii; use Yii;
use yii\codeception\TestCase; use yii\codeception\TestCase;
use app\models\User; use app\models\LoginForm;
use Codeception\Specify;
class LoginFormTest extends TestCase class LoginFormTest extends TestCase
{ {
use \Codeception\Specify; use Specify;
protected function tearDown() protected function tearDown()
{ {
@ -18,10 +19,10 @@ class LoginFormTest extends TestCase
public function testLoginNoUser() public function testLoginNoUser()
{ {
$model = $this->mockUser(null); $model = new LoginForm([
'username' => 'not_existing_username',
$model->username = 'some_username'; 'password' => 'not_existing_password',
$model->password = 'some_password'; ]);
$this->specify('user should not be able to login, when there is no identity', function () use ($model) { $this->specify('user should not be able to login, when there is no identity', function () use ($model) {
expect('model should not login user', $model->login())->false(); expect('model should not login user', $model->login())->false();
@ -31,10 +32,10 @@ class LoginFormTest extends TestCase
public function testLoginWrongPassword() public function testLoginWrongPassword()
{ {
$model = $this->mockUser(new User); $model = new LoginForm([
'username' => 'demo',
$model->username = 'demo'; 'password' => 'wrong_password',
$model->password = 'wrong-password'; ]);
$this->specify('user should not be able to login with wrong password', function () use ($model) { $this->specify('user should not be able to login with wrong password', function () use ($model) {
expect('model should not login user', $model->login())->false(); expect('model should not login user', $model->login())->false();
@ -45,10 +46,10 @@ class LoginFormTest extends TestCase
public function testLoginCorrect() public function testLoginCorrect()
{ {
$model = $this->mockUser(new User(['password' => 'demo'])); $model = new LoginForm([
'username' => 'demo',
$model->username = 'demo'; 'password' => 'demo',
$model->password = 'demo'; ]);
$this->specify('user should be able to login with correct credentials', function () use ($model) { $this->specify('user should be able to login with correct credentials', function () use ($model) {
expect('model should login user', $model->login())->true(); expect('model should login user', $model->login())->true();
@ -57,11 +58,4 @@ class LoginFormTest extends TestCase
}); });
} }
private function mockUser($user)
{
$loginForm = $this->getMock('app\models\LoginForm', ['getUser']);
$loginForm->expects($this->any())->method('getUser')->will($this->returnValue($user));
return $loginForm;
}
} }