mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Рефакторинг common unit тестов
This commit is contained in:
@@ -1,35 +1,27 @@
|
||||
<?php
|
||||
namespace codeception\common\unit\models;
|
||||
|
||||
use Codeception\Specify;
|
||||
use common\models\AccountSession;
|
||||
use tests\codeception\common\unit\TestCase;
|
||||
|
||||
class AccountSessionTest extends TestCase {
|
||||
use Specify;
|
||||
|
||||
public function testGenerateRefreshToken() {
|
||||
$this->specify('method call will set refresh_token value', function() {
|
||||
$model = new AccountSession();
|
||||
$model->generateRefreshToken();
|
||||
expect($model->refresh_token)->notNull();
|
||||
});
|
||||
$model = new AccountSession();
|
||||
$model->generateRefreshToken();
|
||||
$this->assertNotNull($model->refresh_token, 'method call will set refresh_token value');
|
||||
}
|
||||
|
||||
public function testSetIp() {
|
||||
$this->specify('method should convert passed ip string to long', function() {
|
||||
$model = new AccountSession();
|
||||
$model->setIp('127.0.0.1');
|
||||
expect($model->last_used_ip)->equals(2130706433);
|
||||
});
|
||||
$model = new AccountSession();
|
||||
$model->setIp('127.0.0.1');
|
||||
$this->assertEquals(2130706433, $model->last_used_ip, 'method should convert passed ip string to long');
|
||||
}
|
||||
|
||||
public function testGetReadableIp() {
|
||||
$this->specify('method should convert stored ip long into readable ip string', function() {
|
||||
$model = new AccountSession();
|
||||
$model->last_used_ip = 2130706433;
|
||||
expect($model->getReadableIp())->equals('127.0.0.1');
|
||||
});
|
||||
$model = new AccountSession();
|
||||
$model->last_used_ip = 2130706433;
|
||||
$this->assertEquals('127.0.0.1', $model->getReadableIp(), 'method should convert stored long into readable ip');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,27 +6,17 @@ use common\components\UserPass;
|
||||
use common\models\Account;
|
||||
use tests\codeception\common\fixtures\AccountFixture;
|
||||
use tests\codeception\common\fixtures\MojangUsernameFixture;
|
||||
use tests\codeception\common\unit\DbTestCase;
|
||||
use tests\codeception\common\unit\TestCase;
|
||||
use Yii;
|
||||
use const common\LATEST_RULES_VERSION;
|
||||
|
||||
/**
|
||||
* @property array $accounts
|
||||
* @property array $mojangAccounts
|
||||
*/
|
||||
class AccountTest extends DbTestCase {
|
||||
class AccountTest extends TestCase {
|
||||
use Specify;
|
||||
|
||||
public function fixtures() {
|
||||
public function _fixtures() {
|
||||
return [
|
||||
'accounts' => [
|
||||
'class' => AccountFixture::class,
|
||||
'dataFile' => '@tests/codeception/common/fixtures/data/accounts.php',
|
||||
],
|
||||
'mojangAccounts' => [
|
||||
'class' => MojangUsernameFixture::class,
|
||||
'dataFile' => '@tests/codeception/common/fixtures/data/mojang-usernames.php',
|
||||
],
|
||||
'accounts' => AccountFixture::class,
|
||||
'mojangAccounts' => MojangUsernameFixture::class,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -73,7 +63,8 @@ class AccountTest extends DbTestCase {
|
||||
});
|
||||
|
||||
$this->specify('username should be unique', function() {
|
||||
$model = new Account(['username' => $this->accounts['admin']['username']]);
|
||||
$model = new Account();
|
||||
$model->username = $this->tester->grabFixture('accounts', 'admin')['username'];
|
||||
expect($model->validate('username'))->false();
|
||||
expect($model->getErrors('username'))->equals(['error.username_not_available']);
|
||||
});
|
||||
@@ -111,7 +102,7 @@ class AccountTest extends DbTestCase {
|
||||
});
|
||||
|
||||
$this->specify('email should be unique', function() {
|
||||
$model = new Account(['email' => $this->accounts['admin']['email']]);
|
||||
$model = new Account(['email' => $this->tester->grabFixture('accounts', 'admin')['email']]);
|
||||
expect($model->validate('email'))->false();
|
||||
expect($model->getErrors('email'))->equals(['error.email_not_available']);
|
||||
});
|
||||
|
||||
@@ -1,31 +1,35 @@
|
||||
<?php
|
||||
namespace codeception\common\unit\models;
|
||||
|
||||
use Codeception\Specify;
|
||||
use common\models\confirmations\ForgotPassword;
|
||||
use common\models\confirmations\RegistrationConfirmation;
|
||||
use common\models\confirmations;
|
||||
use common\models\EmailActivation;
|
||||
use tests\codeception\common\fixtures\EmailActivationFixture;
|
||||
use tests\codeception\common\unit\DbTestCase;
|
||||
use tests\codeception\common\unit\TestCase;
|
||||
|
||||
class EmailActivationTest extends DbTestCase {
|
||||
use Specify;
|
||||
class EmailActivationTest extends TestCase {
|
||||
|
||||
public function fixtures() {
|
||||
public function _fixtures() {
|
||||
return [
|
||||
'emailActivations' => EmailActivationFixture::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function testInstantiate() {
|
||||
$this->specify('return valid model type', function() {
|
||||
expect(EmailActivation::findOne([
|
||||
'type' => EmailActivation::TYPE_REGISTRATION_EMAIL_CONFIRMATION,
|
||||
]))->isInstanceOf(RegistrationConfirmation::class);
|
||||
expect(EmailActivation::findOne([
|
||||
'type' => EmailActivation::TYPE_FORGOT_PASSWORD_KEY,
|
||||
]))->isInstanceOf(ForgotPassword::class);
|
||||
});
|
||||
$this->assertInstanceOf(confirmations\RegistrationConfirmation::class, EmailActivation::findOne([
|
||||
'type' => EmailActivation::TYPE_REGISTRATION_EMAIL_CONFIRMATION,
|
||||
]));
|
||||
|
||||
$this->assertInstanceOf(confirmations\ForgotPassword::class, EmailActivation::findOne([
|
||||
'type' => EmailActivation::TYPE_FORGOT_PASSWORD_KEY,
|
||||
]));
|
||||
|
||||
$this->assertInstanceOf(confirmations\CurrentEmailConfirmation::class, EmailActivation::findOne([
|
||||
'type' => EmailActivation::TYPE_CURRENT_EMAIL_CONFIRMATION,
|
||||
]));
|
||||
|
||||
$this->assertInstanceOf(confirmations\NewEmailConfirmation::class, EmailActivation::findOne([
|
||||
'type' => EmailActivation::TYPE_NEW_EMAIL_CONFIRMATION,
|
||||
]));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user