Исправлен тест для формы смены ника

Добавлен класс фикстур для таблицы истории ников
This commit is contained in:
ErickSkrauch 2016-07-17 21:01:15 +03:00
parent 681996740d
commit a91ce6ce82
4 changed files with 23 additions and 10 deletions

View File

@ -7,6 +7,7 @@ use common\models\Account;
use common\models\UsernameHistory; use common\models\UsernameHistory;
use tests\codeception\api\unit\DbTestCase; use tests\codeception\api\unit\DbTestCase;
use tests\codeception\common\fixtures\AccountFixture; use tests\codeception\common\fixtures\AccountFixture;
use tests\codeception\common\fixtures\UsernameHistoryFixture;
/** /**
* @property AccountFixture $accounts * @property AccountFixture $accounts
@ -16,10 +17,8 @@ class ChangeUsernameFormTest extends DbTestCase {
public function fixtures() { public function fixtures() {
return [ return [
'accounts' => [ 'accounts' => AccountFixture::class,
'class' => AccountFixture::class, 'history' => UsernameHistoryFixture::class,
'dataFile' => '@tests/codeception/common/fixtures/data/accounts.php',
],
]; ];
} }
@ -36,11 +35,6 @@ class ChangeUsernameFormTest extends DbTestCase {
} }
public function testChangeWithoutChange() { public function testChangeWithoutChange() {
$this->markTestSkipped('This test is written invalid');
return;
// TODO: этот тест написан неправильно - запись всё равно добавляется в базу данных, но тест не замечает
/** @noinspection PhpUnreachableStatementInspection */
$this->specify('no new UsernameHistory record, if we don\'t change nickname', function() { $this->specify('no new UsernameHistory record, if we don\'t change nickname', function() {
$model = $this->createModel([ $model = $this->createModel([
'password' => 'password_0', 'password' => 'password_0',
@ -51,7 +45,7 @@ class ChangeUsernameFormTest extends DbTestCase {
expect(UsernameHistory::findOne([ expect(UsernameHistory::findOne([
'AND', 'AND',
'username' => $this->accounts['admin']['username'], 'username' => $this->accounts['admin']['username'],
['>=', 'applied_in', $callTime - 5], ['>=', 'applied_in', $callTime],
]))->null(); ]))->null();
}); });
} }

View File

@ -9,6 +9,7 @@ use tests\codeception\common\fixtures\EmailActivationFixture;
use tests\codeception\common\fixtures\OauthClientFixture; use tests\codeception\common\fixtures\OauthClientFixture;
use tests\codeception\common\fixtures\OauthScopeFixture; use tests\codeception\common\fixtures\OauthScopeFixture;
use tests\codeception\common\fixtures\OauthSessionFixture; use tests\codeception\common\fixtures\OauthSessionFixture;
use tests\codeception\common\fixtures\UsernameHistoryFixture;
use yii\test\FixtureTrait; use yii\test\FixtureTrait;
use yii\test\InitDbFixture; use yii\test\InitDbFixture;
@ -50,6 +51,7 @@ class FixtureHelper extends Module {
'accounts' => AccountFixture::class, 'accounts' => AccountFixture::class,
'accountSessions' => AccountSessionFixture::class, 'accountSessions' => AccountSessionFixture::class,
'emailActivations' => EmailActivationFixture::class, 'emailActivations' => EmailActivationFixture::class,
'usernamesHistory' => UsernameHistoryFixture::class,
'oauthClients' => [ 'oauthClients' => [
'class' => OauthClientFixture::class, 'class' => OauthClientFixture::class,
'dataFile' => '@tests/codeception/common/fixtures/data/oauth-clients.php', 'dataFile' => '@tests/codeception/common/fixtures/data/oauth-clients.php',

View File

@ -0,0 +1,13 @@
<?php
namespace tests\codeception\common\fixtures;
use common\models\UsernameHistory;
use yii\test\ActiveFixture;
class UsernameHistoryFixture extends ActiveFixture {
public $modelClass = UsernameHistory::class;
public $dataFile = '@tests/codeception/common/fixtures/data/usernames-history.php';
}

View File

@ -0,0 +1,4 @@
<?php
return [
];