mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Рефакторинг api unit тестов
This commit is contained in:
@@ -5,32 +5,27 @@ use api\models\AccountIdentity;
|
||||
use api\traits\AccountFinder;
|
||||
use Codeception\Specify;
|
||||
use common\models\Account;
|
||||
use tests\codeception\api\unit\DbTestCase;
|
||||
use tests\codeception\api\unit\TestCase;
|
||||
use tests\codeception\common\fixtures\AccountFixture;
|
||||
|
||||
/**
|
||||
* @property \tests\codeception\api\UnitTester $actor
|
||||
* @property array $accounts
|
||||
*/
|
||||
class AccountFinderTest extends DbTestCase {
|
||||
class AccountFinderTest extends TestCase {
|
||||
use Specify;
|
||||
|
||||
public function fixtures() {
|
||||
public function _fixtures() {
|
||||
return [
|
||||
'accounts' => [
|
||||
'class' => AccountFixture::class,
|
||||
'dataFile' => '@tests/codeception/common/fixtures/data/accounts.php',
|
||||
],
|
||||
'accounts' => AccountFixture::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function testGetAccount() {
|
||||
$this->specify('founded account for passed login data', function() {
|
||||
$model = new AccountFinderTestTestClass();
|
||||
$model->login = $this->accounts['admin']['email'];
|
||||
/** @var Account $account */
|
||||
$account = $this->tester->grabFixture('accounts', 'admin');
|
||||
$model->login = $account->email;
|
||||
$account = $model->getAccount();
|
||||
expect($account)->isInstanceOf(Account::class);
|
||||
expect($account->id)->equals($this->accounts['admin']['id']);
|
||||
expect($account->id)->equals($account->id);
|
||||
});
|
||||
|
||||
$this->specify('founded account for passed login data with changed account model class name', function() {
|
||||
@@ -40,10 +35,12 @@ class AccountFinderTest extends DbTestCase {
|
||||
return AccountIdentity::class;
|
||||
}
|
||||
};
|
||||
$model->login = $this->accounts['admin']['email'];
|
||||
/** @var Account $account */
|
||||
$account = $this->tester->grabFixture('accounts', 'admin');
|
||||
$model->login = $account->email;
|
||||
$account = $model->getAccount();
|
||||
expect($account)->isInstanceOf(AccountIdentity::class);
|
||||
expect($account->id)->equals($this->accounts['admin']['id']);
|
||||
expect($account->id)->equals($account->id);
|
||||
});
|
||||
|
||||
$this->specify('null, if account not founded', function() {
|
||||
|
||||
@@ -2,41 +2,34 @@
|
||||
namespace tests\codeception\api\traits;
|
||||
|
||||
use api\traits\ApiNormalize;
|
||||
use Codeception\Specify;
|
||||
use Codeception\TestCase\Test;
|
||||
use tests\codeception\api\unit\TestCase;
|
||||
|
||||
class ApiNormalizeTestClass {
|
||||
use ApiNormalize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @property \tests\codeception\api\UnitTester $actor
|
||||
*/
|
||||
class ApiNormalizerTest extends Test {
|
||||
use Specify;
|
||||
class ApiNormalizerTest extends TestCase {
|
||||
|
||||
public function testNormalizeModelErrors() {
|
||||
$object = new ApiNormalizeTestClass();
|
||||
$this->specify('', function() use ($object) {
|
||||
$normalized = $object->normalizeModelErrors([
|
||||
'rulesAgreement' => [
|
||||
'error.you_must_accept_rules',
|
||||
],
|
||||
'email' => [
|
||||
'error.email_required',
|
||||
],
|
||||
'username' => [
|
||||
'error.username_too_short',
|
||||
'error.username_not_unique',
|
||||
],
|
||||
]);
|
||||
$normalized = $object->normalizeModelErrors([
|
||||
'rulesAgreement' => [
|
||||
'error.you_must_accept_rules',
|
||||
],
|
||||
'email' => [
|
||||
'error.email_required',
|
||||
],
|
||||
'username' => [
|
||||
'error.username_too_short',
|
||||
'error.username_not_unique',
|
||||
],
|
||||
]);
|
||||
|
||||
expect($normalized)->equals([
|
||||
'rulesAgreement' => 'error.you_must_accept_rules',
|
||||
'email' => 'error.email_required',
|
||||
'username' => 'error.username_too_short',
|
||||
]);
|
||||
});
|
||||
$this->assertEquals([
|
||||
'rulesAgreement' => 'error.you_must_accept_rules',
|
||||
'email' => 'error.email_required',
|
||||
'username' => 'error.username_too_short',
|
||||
], $normalized);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user