Рефакторинг api unit тестов

This commit is contained in:
ErickSkrauch
2016-10-29 00:47:31 +03:00
parent 7f2602fd29
commit 0e7013d9f5
29 changed files with 358 additions and 620 deletions

View File

@@ -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() {

View File

@@ -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);
}
}