Немного ускорено время прохождения backend тестов за счёт использования прямого обращения к форме логика, а не исполнения запроса

This commit is contained in:
ErickSkrauch 2017-01-08 14:55:28 +03:00
parent 83f32a0f11
commit 4bccf94299

View File

@ -1,9 +1,10 @@
<?php <?php
namespace tests\codeception\api; namespace tests\codeception\api;
use api\components\User\LoginResult;
use api\models\authentication\LoginForm;
use Codeception\Actor; use Codeception\Actor;
use InvalidArgumentException; use InvalidArgumentException;
use tests\codeception\api\_pages\AuthenticationRoute;
/** /**
* Inherited Methods * Inherited Methods
@ -24,19 +25,22 @@ class FunctionalTester extends Actor {
use _generated\FunctionalTesterActions; use _generated\FunctionalTesterActions;
public function loggedInAsActiveAccount($login = null, $password = null) { public function loggedInAsActiveAccount($login = null, $password = null) {
$route = new AuthenticationRoute($this); $form = new LoginForm();
if ($login === null) { if ($login === null && $password === null) {
$route->login('Admin', 'password_0'); $form->login = 'Admin';
$form->password = 'password_0';
} elseif ($login !== null && $password !== null) { } elseif ($login !== null && $password !== null) {
$route->login($login, $password); $form->login = $login;
$form->password = $password;
} else { } else {
throw new InvalidArgumentException('login and password should be presented both.'); throw new InvalidArgumentException('login and password should be presented both.');
} }
$this->canSeeResponseIsJson(); $result = $form->login();
$this->canSeeAuthCredentials(false); $this->assertInstanceOf(LoginResult::class, $result);
$jwt = $this->grabDataFromResponseByJsonPath('$.access_token')[0]; if ($result !== false) {
$this->amBearerAuthenticated($jwt); $this->amBearerAuthenticated($result->getJwt());
}
} }
public function notLoggedIn() { public function notLoggedIn() {