Удалена зависимость от yiisoft/yii2-codeception в пользу интегрированного в Codeception генератора REST адресов

Реорганизованы объекты Pages для Functional тестов
Исправлены не переименованные тесты, оставшиеся после последнего рефакторинга
This commit is contained in:
ErickSkrauch 2017-10-01 03:24:23 +03:00
parent f51bfcb20d
commit 0dbbb2e0de
20 changed files with 101 additions and 205 deletions

View File

@ -26,7 +26,6 @@
"webmozart/assert": "^1.2.0"
},
"require-dev": {
"yiisoft/yii2-codeception": "*",
"yiisoft/yii2-debug": "*",
"yiisoft/yii2-faker": "*",
"flow/jsonpath": "^0.3.1",

View File

@ -1,21 +1,14 @@
<?php
namespace tests\codeception\api\_pages;
use yii\codeception\BasePage;
/**
* @property \tests\codeception\api\FunctionalTester $actor
*/
class AccountsRoute extends BasePage {
public function get(int $accountId) {
$this->route = "/v1/accounts/{$accountId}";
$this->actor->sendGET($this->getUrl());
$this->getActor()->sendGET("/v1/accounts/{$accountId}");
}
public function changePassword(int $accountId, $currentPassword = null, $newPassword = null, $newRePassword = null) {
$this->route = "/v1/accounts/{$accountId}/password";
$this->actor->sendPOST($this->getUrl(), [
$this->getActor()->sendPOST("/v1/accounts/{$accountId}/password", [
'password' => $currentPassword,
'newPassword' => $newPassword,
'newRePassword' => $newRePassword,
@ -23,55 +16,65 @@ class AccountsRoute extends BasePage {
}
public function changeUsername(int $accountId, $currentPassword = null, $newUsername = null) {
$this->route = "/v1/accounts/{$accountId}/username";
$this->actor->sendPOST($this->getUrl(), [
$this->getActor()->sendPOST("/v1/accounts/{$accountId}/username", [
'password' => $currentPassword,
'username' => $newUsername,
]);
}
public function changeEmailInitialize(int $accountId, $password = '') {
$this->route = "/v1/accounts/{$accountId}/email-verification";
$this->actor->sendPOST($this->getUrl(), [
$this->getActor()->sendPOST("/v1/accounts/{$accountId}/email-verification", [
'password' => $password,
]);
}
public function changeEmailSubmitNewEmail(int $accountId, $key = null, $email = null) {
$this->route = "/v1/accounts/{$accountId}/new-email-verification";
$this->actor->sendPOST($this->getUrl(), [
$this->getActor()->sendPOST("/v1/accounts/{$accountId}/new-email-verification", [
'key' => $key,
'email' => $email,
]);
}
public function changeEmail(int $accountId, $key = null) {
$this->route = "/v1/accounts/{$accountId}/email";
$this->actor->sendPOST($this->getUrl(), [
$this->getActor()->sendPOST("/v1/accounts/{$accountId}/email", [
'key' => $key,
]);
}
public function changeLanguage(int $accountId, $lang = null) {
$this->route = "/v1/accounts/{$accountId}/language";
$this->actor->sendPOST($this->getUrl(), [
$this->getActor()->sendPOST("/v1/accounts/{$accountId}/language", [
'lang' => $lang,
]);
}
public function acceptRules(int $accountId) {
$this->route = "/v1/accounts/{$accountId}/rules";
$this->actor->sendPOST($this->getUrl());
$this->getActor()->sendPOST("/v1/accounts/{$accountId}/rules");
}
public function getTwoFactorAuthCredentials(int $accountId) {
$this->getActor()->sendGET("/v1/accounts/{$accountId}/two-factor-auth");
}
public function enableTwoFactorAuth(int $accountId, $totp = null, $password = null) {
$this->getActor()->sendPOST("/v1/accounts/{$accountId}/two-factor-auth", [
'totp' => $totp,
'password' => $password,
]);
}
public function disableTwoFactorAuth(int $accountId, $totp = null, $password = null) {
$this->getActor()->sendDELETE("/v1/accounts/{$accountId}/two-factor-auth", [
'totp' => $totp,
'password' => $password,
]);
}
public function ban(int $accountId) {
$this->route = "/v1/accounts/{$accountId}/ban";
$this->actor->sendPOST($this->getUrl());
$this->getActor()->sendPOST("/v1/accounts/{$accountId}/ban");
}
public function pardon($accountId) {
$this->route = "/v1/accounts/{$accountId}/ban";
$this->actor->sendDELETE($this->getUrl());
public function pardon(int $accountId) {
$this->getActor()->sendDELETE("/v1/accounts/{$accountId}/ban");
}
}

View File

@ -1,11 +1,6 @@
<?php
namespace tests\codeception\api\_pages;
use yii\codeception\BasePage;
/**
* @property \tests\codeception\api\FunctionalTester $actor
*/
class AuthenticationRoute extends BasePage {
/**
@ -15,7 +10,6 @@ class AuthenticationRoute extends BasePage {
* @param bool $rememberMe
*/
public function login($login = '', $password = '', $rememberMeOrToken = null, $rememberMe = false) {
$this->route = ['authentication/login'];
$params = [
'login' => $login,
'password' => $password,
@ -27,25 +21,22 @@ class AuthenticationRoute extends BasePage {
$params['totp'] = $rememberMeOrToken;
}
$this->actor->sendPOST($this->getUrl(), $params);
$this->getActor()->sendPOST('/authentication/login', $params);
}
public function logout() {
$this->route = ['authentication/logout'];
$this->actor->sendPOST($this->getUrl());
$this->getActor()->sendPOST('/authentication/logout');
}
public function forgotPassword($login = null, $token = null) {
$this->route = ['authentication/forgot-password'];
$this->actor->sendPOST($this->getUrl(), [
$this->getActor()->sendPOST('/authentication/forgot-password', [
'login' => $login,
'totp' => $token,
]);
}
public function recoverPassword($key = null, $newPassword = null, $newRePassword = null) {
$this->route = ['authentication/recover-password'];
$this->actor->sendPOST($this->getUrl(), [
$this->getActor()->sendPOST('/authentication/recover-password', [
'key' => $key,
'newPassword' => $newPassword,
'newRePassword' => $newRePassword,
@ -53,8 +44,7 @@ class AuthenticationRoute extends BasePage {
}
public function refreshToken($refreshToken = null) {
$this->route = ['authentication/refresh-token'];
$this->actor->sendPOST($this->getUrl(), [
$this->getActor()->sendPOST('/authentication/refresh-token', [
'refresh_token' => $refreshToken,
]);
}

View File

@ -1,36 +1,26 @@
<?php
namespace tests\codeception\api\_pages;
use yii\codeception\BasePage;
/**
* @property \tests\codeception\api\FunctionalTester $actor
*/
class AuthserverRoute extends BasePage {
public function authenticate($params) {
$this->route = ['authserver/authentication/authenticate'];
$this->actor->sendPOST($this->getUrl(), $params);
$this->getActor()->sendPOST('/authserver/authentication/authenticate', $params);
}
public function refresh($params) {
$this->route = ['authserver/authentication/refresh'];
$this->actor->sendPOST($this->getUrl(), $params);
$this->getActor()->sendPOST('/authserver/authentication/refresh', $params);
}
public function validate($params) {
$this->route = ['authserver/authentication/validate'];
$this->actor->sendPOST($this->getUrl(), $params);
$this->getActor()->sendPOST('/authserver/authentication/validate', $params);
}
public function invalidate($params) {
$this->route = ['authserver/authentication/invalidate'];
$this->actor->sendPOST($this->getUrl(), $params);
$this->getActor()->sendPOST('/authserver/authentication/invalidate', $params);
}
public function signout($params) {
$this->route = ['authserver/authentication/signout'];
$this->actor->sendPOST($this->getUrl(), $params);
$this->getActor()->sendPOST('/authserver/authentication/signout', $params);
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace tests\codeception\api\_pages;
use tests\codeception\api\FunctionalTester;
class BasePage {
/**
* @var FunctionalTester
*/
private $actor;
public function __construct(FunctionalTester $I) {
$this->actor = $I;
}
public function getActor(): FunctionalTester {
return $this->actor;
}
}

View File

@ -1,16 +1,10 @@
<?php
namespace tests\codeception\api\_pages;
use yii\codeception\BasePage;
/**
* @property \tests\codeception\api\FunctionalTester $actor
*/
class IdentityInfoRoute extends BasePage {
public function info() {
$this->route = ['identity-info/index'];
$this->actor->sendGET($this->getUrl());
$this->getActor()->sendGET('/account/v1/info');
}
}

View File

@ -1,16 +1,10 @@
<?php
namespace tests\codeception\api\_pages;
use yii\codeception\BasePage;
/**
* @property \tests\codeception\api\FunctionalTester $actor
*/
class InternalRoute extends BasePage {
public function info(string $param, string $value) {
$this->route = '/internal/accounts/info';
$this->actor->sendGET($this->getUrl(), [$param => $value]);
$this->getActor()->sendGET('/internal/accounts/info', [$param => $value]);
}
}

View File

@ -1,20 +0,0 @@
<?php
namespace tests\codeception\api\_pages;
use yii\codeception\BasePage;
/**
* @property \tests\codeception\api\FunctionalTester $actor
*/
class LoginRoute extends BasePage {
public $route = ['authentication/login'];
public function login($login = '', $password = '') {
$this->actor->sendPOST($this->getUrl(), [
'login' => $login,
'password' => $password,
]);
}
}

View File

@ -1,27 +1,19 @@
<?php
namespace tests\codeception\api\_pages;
use yii\codeception\BasePage;
/**
* @property \tests\codeception\api\FunctionalTester $actor
*/
class MojangApiRoute extends BasePage {
public function usernameToUuid($username, $at = null) {
$this->route = '/mojang/profiles/' . $username;
$params = $at === null ? [] : ['at' => $at];
$this->actor->sendGET($this->getUrl(), $params);
$this->getActor()->sendGET("/mojang/profiles/{$username}", $params);
}
public function usernamesByUuid($uuid) {
$this->route = "/mojang/profiles/{$uuid}/names";
$this->actor->sendGET($this->getUrl());
$this->getActor()->sendGET("/mojang/profiles/{$uuid}/names");
}
public function uuidsByUsernames($uuids) {
$this->route = '/mojang/profiles';
$this->actor->sendPOST($this->getUrl(), $uuids);
$this->getActor()->sendPOST('/mojang/profiles', $uuids);
}
}

View File

@ -1,26 +1,18 @@
<?php
namespace tests\codeception\api\_pages;
use yii\codeception\BasePage;
/**
* @property \tests\codeception\api\FunctionalTester $actor
*/
class OauthRoute extends BasePage {
public function validate($queryParams) {
$this->route = '/oauth2/v1/validate';
$this->actor->sendGET($this->getUrl($queryParams));
$this->getActor()->sendGET('/oauth2/v1/validate', $queryParams);
}
public function complete($queryParams = [], $postParams = []) {
$this->route = '/oauth2/v1/complete';
$this->actor->sendPOST($this->getUrl($queryParams), $postParams);
$this->getActor()->sendPOST('/oauth2/v1/complete?' . http_build_query($queryParams), $postParams);
}
public function issueToken($postParams = []) {
$this->route = '/oauth2/v1/token';
$this->actor->sendPOST($this->getUrl(), $postParams);
$this->getActor()->sendPOST('/oauth2/v1/token', $postParams);
}
}

View File

@ -1,16 +1,10 @@
<?php
namespace tests\codeception\api\_pages;
use yii\codeception\BasePage;
/**
* @property \tests\codeception\api\FunctionalTester $actor
*/
class OptionsRoute extends BasePage {
public function get() {
$this->route = ['options/index'];
$this->actor->sendGET($this->getUrl());
$this->getActor()->sendGET('/options');
}
}

View File

@ -1,36 +1,26 @@
<?php
namespace tests\codeception\api\_pages;
use yii\codeception\BasePage;
/**
* @property \tests\codeception\api\FunctionalTester $actor
*/
class SessionServerRoute extends BasePage {
public function join($params) {
$this->route = '/minecraft/session/join';
$this->actor->sendPOST($this->getUrl(), $params);
$this->getActor()->sendPOST('/minecraft/session/join', $params);
}
public function joinLegacy(array $params) {
$this->route = '/minecraft/session/legacy/join';
$this->actor->sendGET($this->getUrl(), $params);
$this->getActor()->sendGET('/minecraft/session/legacy/join', $params);
}
public function hasJoined(array $params) {
$this->route = '/minecraft/session/hasJoined';
$this->actor->sendGET($this->getUrl(), $params);
$this->getActor()->sendGET('/minecraft/session/hasJoined', $params);
}
public function hasJoinedLegacy(array $params) {
$this->route = '/minecraft/session/legacy/hasJoined';
$this->actor->sendGET($this->getUrl(), $params);
$this->getActor()->sendGET('/minecraft/session/legacy/hasJoined', $params);
}
public function profile($profileUuid) {
$this->route = '/minecraft/session/profile/' . $profileUuid;
$this->actor->sendGET($this->getUrl());
$this->getActor()->sendGET("/minecraft/session/profile/{$profileUuid}");
}
}

View File

@ -1,26 +1,18 @@
<?php
namespace tests\codeception\api\_pages;
use yii\codeception\BasePage;
/**
* @property \tests\codeception\api\FunctionalTester $actor
*/
class SignupRoute extends BasePage {
public function register(array $registrationData) {
$this->route = ['signup/index'];
$this->actor->sendPOST($this->getUrl(), $registrationData);
$this->getActor()->sendPOST('/signup', $registrationData);
}
public function sendRepeatMessage($email = '') {
$this->route = ['signup/repeat-message'];
$this->actor->sendPOST($this->getUrl(), ['email' => $email]);
$this->getActor()->sendPOST('/signup/repeat-message', ['email' => $email]);
}
public function confirm($key = '') {
$this->route = ['signup/confirm'];
$this->actor->sendPOST($this->getUrl(), [
$this->getActor()->sendPOST('/signup/confirm', [
'key' => $key,
]);
}

View File

@ -1,36 +0,0 @@
<?php
namespace tests\codeception\api\_pages;
use yii\codeception\BasePage;
/**
* @property \tests\codeception\api\FunctionalTester $actor
*/
class TwoFactorAuthRoute extends BasePage {
public function credentials(int $accountId) {
$this->setRoute($accountId);
$this->actor->sendGET($this->getUrl());
}
public function enable(int $accountId, $totp = null, $password = null) {
$this->setRoute($accountId);
$this->actor->sendPOST($this->getUrl(), [
'totp' => $totp,
'password' => $password,
]);
}
public function disable(int $accountId, $totp = null, $password = null) {
$this->setRoute($accountId);
$this->actor->sendDELETE($this->getUrl(), [
'totp' => $totp,
'password' => $password,
]);
}
private function setRoute(int $accountId) {
$this->route = "/v1/accounts/{$accountId}/two-factor-auth";
}
}

View File

@ -10,6 +10,7 @@ modules:
- Asserts
- REST:
depends: Yii2
url: /api
config:
Yii2:
configFile: '../config/api/functional.php'

View File

@ -6,7 +6,7 @@ use tests\codeception\api\_pages\AccountsRoute;
use tests\codeception\api\functional\_steps\OauthSteps;
use tests\codeception\api\FunctionalTester;
class AccountBanCest {
class AccountsBanCest {
/**
* @var AccountsRoute

View File

@ -2,24 +2,24 @@
namespace tests\codeception\api\functional;
use OTPHP\TOTP;
use tests\codeception\api\_pages\TwoFactorAuthRoute;
use tests\codeception\api\_pages\AccountsRoute;
use tests\codeception\api\FunctionalTester;
class TwoFactorAuthDisableCest {
class AccountsDisableTwoFactorAuthCest {
/**
* @var TwoFactorAuthRoute
* @var AccountsRoute
*/
private $route;
public function _before(FunctionalTester $I) {
$this->route = new TwoFactorAuthRoute($I);
$this->route = new AccountsRoute($I);
}
public function testFails(FunctionalTester $I) {
$accountId = $I->amAuthenticated('AccountWithEnabledOtp');
$this->route->disable($accountId);
$this->route->disableTwoFactorAuth($accountId);
$I->canSeeResponseContainsJson([
'success' => false,
'errors' => [
@ -28,7 +28,7 @@ class TwoFactorAuthDisableCest {
],
]);
$this->route->disable($accountId, '123456', 'invalid_password');
$this->route->disableTwoFactorAuth($accountId, '123456', 'invalid_password');
$I->canSeeResponseContainsJson([
'success' => false,
'errors' => [
@ -38,7 +38,7 @@ class TwoFactorAuthDisableCest {
]);
$accountId = $I->amAuthenticated('AccountWithOtpSecret');
$this->route->disable($accountId, '123456', 'invalid_password');
$this->route->disableTwoFactorAuth($accountId, '123456', 'invalid_password');
$I->canSeeResponseContainsJson([
'success' => false,
'errors' => [
@ -50,7 +50,7 @@ class TwoFactorAuthDisableCest {
public function testSuccessEnable(FunctionalTester $I) {
$accountId = $I->amAuthenticated('AccountWithEnabledOtp');
$totp = TOTP::create('BBBB');
$this->route->disable($accountId, $totp->now(), 'password_0');
$this->route->disableTwoFactorAuth($accountId, $totp->now(), 'password_0');
$I->canSeeResponseCodeIs(200);
$I->canSeeResponseIsJson();
$I->canSeeResponseContainsJson([

View File

@ -2,24 +2,24 @@
namespace tests\codeception\api\functional;
use OTPHP\TOTP;
use tests\codeception\api\_pages\TwoFactorAuthRoute;
use tests\codeception\api\_pages\AccountsRoute;
use tests\codeception\api\FunctionalTester;
class TwoFactorAuthEnableCest {
class AccountsEnableTwoFactorAuthCest {
/**
* @var TwoFactorAuthRoute
* @var AccountsRoute
*/
private $route;
public function _before(FunctionalTester $I) {
$this->route = new TwoFactorAuthRoute($I);
$this->route = new AccountsRoute($I);
}
public function testFails(FunctionalTester $I) {
$accountId = $I->amAuthenticated('AccountWithOtpSecret');
$this->route->enable($accountId);
$this->route->enableTwoFactorAuth($accountId);
$I->canSeeResponseContainsJson([
'success' => false,
'errors' => [
@ -28,7 +28,7 @@ class TwoFactorAuthEnableCest {
],
]);
$this->route->enable($accountId, '123456', 'invalid_password');
$this->route->enableTwoFactorAuth($accountId, '123456', 'invalid_password');
$I->canSeeResponseContainsJson([
'success' => false,
'errors' => [
@ -38,7 +38,7 @@ class TwoFactorAuthEnableCest {
]);
$accountId = $I->amAuthenticated('AccountWithEnabledOtp');
$this->route->enable($accountId, '123456', 'invalid_password');
$this->route->enableTwoFactorAuth($accountId, '123456', 'invalid_password');
$I->canSeeResponseContainsJson([
'success' => false,
'errors' => [
@ -50,7 +50,7 @@ class TwoFactorAuthEnableCest {
public function testSuccessEnable(FunctionalTester $I) {
$accountId = $I->amAuthenticated('AccountWithOtpSecret');
$totp = TOTP::create('AAAA');
$this->route->enable($accountId, $totp->now(), 'password_0');
$this->route->enableTwoFactorAuth($accountId, $totp->now(), 'password_0');
$I->canSeeResponseCodeIs(200);
$I->canSeeResponseIsJson();
$I->canSeeResponseContainsJson([

View File

@ -6,7 +6,7 @@ use tests\codeception\api\_pages\AccountsRoute;
use tests\codeception\api\functional\_steps\OauthSteps;
use tests\codeception\api\FunctionalTester;
class AccountPardonCest {
class AccountsPardonCest {
/**
* @var AccountsRoute

View File

@ -1,23 +1,23 @@
<?php
namespace tests\codeception\api\functional;
use tests\codeception\api\_pages\TwoFactorAuthRoute;
use tests\codeception\api\_pages\AccountsRoute;
use tests\codeception\api\FunctionalTester;
class TwoFactorAuthCredentialsCest {
class AccountsTwoFactorAuthCredentialsCest {
/**
* @var TwoFactorAuthRoute
* @var AccountsRoute
*/
private $route;
public function _before(FunctionalTester $I) {
$this->route = new TwoFactorAuthRoute($I);
$this->route = new AccountsRoute($I);
}
public function testGetCredentials(FunctionalTester $I) {
$accountId = $I->amAuthenticated();
$this->route->credentials($accountId);
$this->route->getTwoFactorAuthCredentials($accountId);
$I->canSeeResponseCodeIs(200);
$I->canSeeResponseIsJson();
$I->canSeeResponseJsonMatchesJsonPath('$.secret');