mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Cleanup code, improve typings
This commit is contained in:
@@ -126,8 +126,8 @@ class ForgotPasswordFormTest extends TestCase {
|
||||
return new class($params) extends ForgotPasswordForm {
|
||||
public $key;
|
||||
|
||||
public function getEmailActivation() {
|
||||
return EmailActivation::findOne($this->key);
|
||||
public function getEmailActivation(): ?EmailActivation {
|
||||
return EmailActivation::findOne(['key' => $this->key]);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ class RepeatAccountActivationFormTest extends TestCase {
|
||||
return new class($params) extends RepeatAccountActivationForm {
|
||||
public $emailKey;
|
||||
|
||||
public function getActivation() {
|
||||
public function getActivation(): ?EmailActivation {
|
||||
return EmailActivation::findOne($this->emailKey);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -29,7 +29,6 @@ class ChangeEmailFormTest extends TestCase {
|
||||
'account_id' => $account->id,
|
||||
'type' => EmailActivation::TYPE_NEW_EMAIL_CONFIRMATION,
|
||||
]));
|
||||
/** @noinspection UnserializeExploitsInspection */
|
||||
$data = unserialize($newEmailConfirmationFixture['_data']);
|
||||
$this->assertSame($data['newEmail'], $account->email);
|
||||
}
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
<?php
|
||||
namespace api\tests\_support\traits;
|
||||
|
||||
use api\tests\unit\TestCase;
|
||||
use api\traits\AccountFinder;
|
||||
use common\models\Account;
|
||||
use common\tests\fixtures\AccountFixture;
|
||||
|
||||
class AccountFinderTest extends TestCase {
|
||||
|
||||
public function _fixtures(): array {
|
||||
return [
|
||||
'accounts' => AccountFixture::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function testGetAccount() {
|
||||
$model = new AccountFinderTestTestClass();
|
||||
/** @var Account $account */
|
||||
$accountFixture = $this->tester->grabFixture('accounts', 'admin');
|
||||
$model->login = $accountFixture->email;
|
||||
$account = $model->getAccount();
|
||||
$this->assertInstanceOf(Account::class, $account);
|
||||
$this->assertSame($accountFixture->id, $account->id, 'founded account for passed login data');
|
||||
|
||||
$model = new AccountFinderTestTestClass();
|
||||
$model->login = 'unexpected';
|
||||
$this->assertNull($account = $model->getAccount(), 'null, if account can\'t be found');
|
||||
}
|
||||
|
||||
public function testGetLoginAttribute() {
|
||||
$model = new AccountFinderTestTestClass();
|
||||
$model->login = 'erickskrauch@ely.by';
|
||||
$this->assertSame('email', $model->getLoginAttribute(), 'if login look like email value, then \'email\'');
|
||||
|
||||
$model = new AccountFinderTestTestClass();
|
||||
$model->login = 'erickskrauch';
|
||||
$this->assertSame('username', $model->getLoginAttribute(), 'username in any other case');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class AccountFinderTestTestClass {
|
||||
use AccountFinder;
|
||||
|
||||
public $login;
|
||||
|
||||
public function getLogin(): string {
|
||||
return $this->login;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user