mirror of
https://github.com/elyby/accounts.git
synced 2024-12-25 06:39:46 +05:30
Обновлён Codeception до версии 2.1
This commit is contained in:
parent
455d7b9469
commit
ce2e68faf6
@ -63,9 +63,9 @@ docker-compose restart
|
||||
|
||||
```sh
|
||||
# Прежде чем тестировать, необходимо накатить миграции
|
||||
docker exec -it db6366f120ee php tests/codeception/bin/yii migrate --interactive=0
|
||||
docker exec -it app php tests/codeception/bin/yii migrate --interactive=0
|
||||
# Собрать все тестовые окружения
|
||||
docker exec -it db6366f120ee /bin/sh -c 'cd tests; ./../vendor/bin/codecept build'
|
||||
docker exec -it app ./vendor/bin/codecept build -c tests
|
||||
# И запустить собственно процесс тестирования
|
||||
docker exec -it db6366f120ee /bin/sh -c 'cd tests; ./../vendor/bin/codecept run'
|
||||
docker exec -it app ./vendor/bin/codecept run -c tests
|
||||
```
|
||||
|
@ -32,7 +32,7 @@
|
||||
"yiisoft/yii2-gii": "*",
|
||||
"yiisoft/yii2-faker": "*",
|
||||
"flow/jsonpath": "^0.3.1",
|
||||
"codeception/codeception": "2.0.*",
|
||||
"codeception/codeception": "2.1.*",
|
||||
"codeception/specify": "*",
|
||||
"codeception/verify": "*"
|
||||
},
|
||||
|
3
tests/codeception/api/.gitignore
vendored
3
tests/codeception/api/.gitignore
vendored
@ -1,3 +1,2 @@
|
||||
# these files are auto generated by codeception build
|
||||
/unit/UnitTester.php
|
||||
/functional/FunctionalTester.php
|
||||
_support/_generated
|
||||
|
38
tests/codeception/api/_support/FunctionalTester.php
Normal file
38
tests/codeception/api/_support/FunctionalTester.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
namespace tests\codeception\api;
|
||||
|
||||
use tests\codeception\api\_pages\LoginRoute;
|
||||
|
||||
/**
|
||||
* Inherited Methods
|
||||
* @method void wantToTest($text)
|
||||
* @method void wantTo($text)
|
||||
* @method void execute($callable)
|
||||
* @method void expectTo($prediction)
|
||||
* @method void expect($prediction)
|
||||
* @method void amGoingTo($argumentation)
|
||||
* @method void am($role)
|
||||
* @method void lookForwardTo($achieveValue)
|
||||
* @method void comment($description)
|
||||
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
|
||||
*
|
||||
* @SuppressWarnings(PHPMD)
|
||||
*/
|
||||
class FunctionalTester extends \Codeception\Actor {
|
||||
use _generated\FunctionalTesterActions;
|
||||
|
||||
public function loggedInAsActiveAccount() {
|
||||
$I = $this;
|
||||
$route = new LoginRoute($I);
|
||||
$route->login('Admin', 'password_0');
|
||||
$I->canSeeResponseIsJson();
|
||||
$I->canSeeResponseJsonMatchesJsonPath('$.jwt');
|
||||
$jwt = $I->grabDataFromResponseByJsonPath('$.jwt')[0];
|
||||
$I->amBearerAuthenticated($jwt);
|
||||
}
|
||||
|
||||
public function notLoggedIn() {
|
||||
$this->haveHttpHeader('Authorization', null);
|
||||
}
|
||||
|
||||
}
|
26
tests/codeception/api/_support/UnitTester.php
Normal file
26
tests/codeception/api/_support/UnitTester.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace tests\codeception\api;
|
||||
|
||||
/**
|
||||
* Inherited Methods
|
||||
* @method void wantToTest($text)
|
||||
* @method void wantTo($text)
|
||||
* @method void execute($callable)
|
||||
* @method void expectTo($prediction)
|
||||
* @method void expect($prediction)
|
||||
* @method void amGoingTo($argumentation)
|
||||
* @method void am($role)
|
||||
* @method void lookForwardTo($achieveValue)
|
||||
* @method void comment($description)
|
||||
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
|
||||
*
|
||||
* @SuppressWarnings(PHPMD)
|
||||
*/
|
||||
class UnitTester extends \Codeception\Actor
|
||||
{
|
||||
use _generated\UnitTesterActions;
|
||||
|
||||
/**
|
||||
* Define custom actions here
|
||||
*/
|
||||
}
|
@ -1,12 +1,13 @@
|
||||
class_name: FunctionalTester
|
||||
modules:
|
||||
enabled:
|
||||
- Filesystem
|
||||
- Yii2
|
||||
- tests\codeception\common\_support\FixtureHelper
|
||||
- REST
|
||||
- Redis
|
||||
- AMQP
|
||||
- Filesystem
|
||||
- Yii2
|
||||
- tests\codeception\common\_support\FixtureHelper
|
||||
- REST:
|
||||
depends: Yii2
|
||||
- Redis
|
||||
- AMQP
|
||||
config:
|
||||
Yii2:
|
||||
configFile: '../config/api/functional.php'
|
||||
|
@ -1,12 +1,10 @@
|
||||
<?php
|
||||
namespace tests\codeception\api\functional;
|
||||
|
||||
use Codeception\Scenario;
|
||||
use Codeception\Specify;
|
||||
use common\models\Account;
|
||||
use tests\codeception\api\_pages\AccountsRoute;
|
||||
use tests\codeception\api\_pages\LoginRoute;
|
||||
use tests\codeception\api\functional\_steps\AccountSteps;
|
||||
use tests\codeception\api\FunctionalTester;
|
||||
|
||||
class AccountsChangePasswordCest {
|
||||
@ -20,16 +18,15 @@ class AccountsChangePasswordCest {
|
||||
$this->route = new AccountsRoute($I);
|
||||
}
|
||||
|
||||
public function _after(FunctionalTester $I) {
|
||||
public function _after() {
|
||||
/** @var Account $account */
|
||||
$account = Account::findOne(1);
|
||||
$account->setPassword('password_0');
|
||||
$account->save();
|
||||
}
|
||||
|
||||
public function testChangePassword(FunctionalTester $I, Scenario $scenario) {
|
||||
public function testChangePassword(FunctionalTester $I) {
|
||||
$I->wantTo('change my password');
|
||||
$I = new AccountSteps($scenario);
|
||||
$I->loggedInAsActiveAccount();
|
||||
|
||||
$this->route->changePassword('password_0', 'new-password', 'new-password');
|
||||
|
@ -1,11 +1,9 @@
|
||||
<?php
|
||||
namespace tests\codeception\api\functional;
|
||||
|
||||
use Codeception\Scenario;
|
||||
use Codeception\Specify;
|
||||
use common\models\Account;
|
||||
use tests\codeception\api\_pages\AccountsRoute;
|
||||
use tests\codeception\api\functional\_steps\AccountSteps;
|
||||
use tests\codeception\api\FunctionalTester;
|
||||
|
||||
class AccountsChangeUsernameCest {
|
||||
@ -19,16 +17,15 @@ class AccountsChangeUsernameCest {
|
||||
$this->route = new AccountsRoute($I);
|
||||
}
|
||||
|
||||
public function _after(FunctionalTester $I) {
|
||||
public function _after() {
|
||||
/** @var Account $account */
|
||||
$account = Account::findOne(1);
|
||||
$account->username = 'Admin';
|
||||
$account->save();
|
||||
}
|
||||
|
||||
public function testChangeUsername(FunctionalTester $I, Scenario $scenario) {
|
||||
public function testChangeUsername(FunctionalTester $I) {
|
||||
$I->wantTo('change my nickname');
|
||||
$I = new AccountSteps($scenario);
|
||||
$I->loggedInAsActiveAccount();
|
||||
|
||||
$this->route->changeUsername('password_0', 'bruce_wayne');
|
||||
@ -39,9 +36,8 @@ class AccountsChangeUsernameCest {
|
||||
]);
|
||||
}
|
||||
|
||||
public function testChangeUsernameNotAvailable(FunctionalTester $I, Scenario $scenario) {
|
||||
public function testChangeUsernameNotAvailable(FunctionalTester $I) {
|
||||
$I->wantTo('see, that nickname "in use" is not available');
|
||||
$I = new AccountSteps($scenario);
|
||||
$I->loggedInAsActiveAccount();
|
||||
|
||||
$this->route->changeUsername('password_0', 'Jon');
|
||||
|
@ -1,10 +1,8 @@
|
||||
<?php
|
||||
namespace tests\codeception\api\functional;
|
||||
|
||||
use Codeception\Scenario;
|
||||
use Codeception\Specify;
|
||||
use tests\codeception\api\_pages\AccountsRoute;
|
||||
use tests\codeception\api\functional\_steps\AccountSteps;
|
||||
use tests\codeception\api\FunctionalTester;
|
||||
|
||||
class AccountsCurrentCest {
|
||||
@ -18,8 +16,7 @@ class AccountsCurrentCest {
|
||||
$this->route = new AccountsRoute($I);
|
||||
}
|
||||
|
||||
public function testCurrent(FunctionalTester $I, Scenario $scenario) {
|
||||
$I = new AccountSteps($scenario);
|
||||
public function testCurrent(FunctionalTester $I) {
|
||||
$I->loggedInAsActiveAccount();
|
||||
|
||||
$this->route->current();
|
||||
|
@ -1,7 +1,6 @@
|
||||
<?php
|
||||
namespace tests\codeception\api;
|
||||
|
||||
use Codeception\Scenario;
|
||||
use tests\codeception\api\_pages\OauthRoute;
|
||||
use tests\codeception\api\functional\_steps\OauthSteps;
|
||||
use Yii;
|
||||
@ -38,8 +37,7 @@ class OauthAccessTokenCest {
|
||||
]);
|
||||
}
|
||||
|
||||
public function testIssueToken(FunctionalTester $I, Scenario $scenario) {
|
||||
$I = new OauthSteps($scenario);
|
||||
public function testIssueToken(OauthSteps $I) {
|
||||
$authCode = $I->getAuthCode();
|
||||
$this->route->issueToken($this->buildParams(
|
||||
$authCode,
|
||||
@ -56,8 +54,7 @@ class OauthAccessTokenCest {
|
||||
$I->canSeeResponseJsonMatchesJsonPath('$.expires_in');
|
||||
}
|
||||
|
||||
public function testIssueTokenWithRefreshToken(FunctionalTester $I, Scenario $scenario) {
|
||||
$I = new OauthSteps($scenario);
|
||||
public function testIssueTokenWithRefreshToken(OauthSteps $I) {
|
||||
$authCode = $I->getAuthCode(false);
|
||||
$this->route->issueToken($this->buildParams(
|
||||
$authCode,
|
||||
|
@ -2,7 +2,6 @@
|
||||
namespace tests\codeception\api;
|
||||
|
||||
use tests\codeception\api\_pages\OauthRoute;
|
||||
use tests\codeception\api\functional\_steps\AccountSteps;
|
||||
use Yii;
|
||||
|
||||
class OauthAuthCodeCest {
|
||||
@ -54,6 +53,7 @@ class OauthAuthCodeCest {
|
||||
}
|
||||
|
||||
public function testValidateWithDescriptionReplaceRequest(FunctionalTester $I) {
|
||||
$I->loggedInAsActiveAccount();
|
||||
$I->wantTo('validate and get information with description replacement');
|
||||
$this->route->validate($this->buildQueryParams(
|
||||
'ely',
|
||||
@ -74,15 +74,13 @@ class OauthAuthCodeCest {
|
||||
]);
|
||||
}
|
||||
|
||||
public function testCompleteValidationAction($I, $scenario) {
|
||||
$I = new AccountSteps($scenario);
|
||||
public function testCompleteValidationAction(FunctionalTester $I) {
|
||||
$I->loggedInAsActiveAccount();
|
||||
$I->wantTo('validate all oAuth params on complete request');
|
||||
$this->testOauthParamsValidation($I, 'complete');
|
||||
}
|
||||
|
||||
public function testCompleteActionOnWrongConditions($I, $scenario) {
|
||||
$I = new AccountSteps($scenario);
|
||||
public function testCompleteActionOnWrongConditions(FunctionalTester $I) {
|
||||
$I->loggedInAsActiveAccount();
|
||||
|
||||
$I->wantTo('get accept_required if I dom\'t require any scope, but this is first time request');
|
||||
@ -116,10 +114,8 @@ class OauthAuthCodeCest {
|
||||
]);
|
||||
}
|
||||
|
||||
public function testCompleteActionSuccess($I, $scenario) {
|
||||
$I = new AccountSteps($scenario);
|
||||
public function testCompleteActionSuccess(FunctionalTester $I) {
|
||||
$I->loggedInAsActiveAccount();
|
||||
|
||||
$I->wantTo('get auth code if I require some scope and pass accept field');
|
||||
$this->route->complete($this->buildQueryParams(
|
||||
'ely',
|
||||
@ -161,8 +157,7 @@ class OauthAuthCodeCest {
|
||||
$I->canSeeResponseJsonMatchesJsonPath('$.redirectUri');
|
||||
}
|
||||
|
||||
public function testAcceptRequiredOnNewScope($I, $scenario) {
|
||||
$I = new AccountSteps($scenario);
|
||||
public function testAcceptRequiredOnNewScope(FunctionalTester $I) {
|
||||
$I->loggedInAsActiveAccount();
|
||||
$I->wantTo('get accept_required if I have previous successful request, but now require some new scope');
|
||||
$this->route->complete($this->buildQueryParams(
|
||||
@ -186,8 +181,7 @@ class OauthAuthCodeCest {
|
||||
]);
|
||||
}
|
||||
|
||||
public function testCompleteActionWithDismissState($I, $scenario) {
|
||||
$I = new AccountSteps($scenario);
|
||||
public function testCompleteActionWithDismissState(FunctionalTester $I) {
|
||||
$I->loggedInAsActiveAccount();
|
||||
$I->wantTo('get access_denied error if I pass accept in false state');
|
||||
$this->route->complete($this->buildQueryParams(
|
||||
|
@ -1,7 +1,6 @@
|
||||
<?php
|
||||
namespace tests\codeception\api;
|
||||
|
||||
use Codeception\Scenario;
|
||||
use common\models\OauthScope;
|
||||
use tests\codeception\api\_pages\OauthRoute;
|
||||
use tests\codeception\api\functional\_steps\OauthSteps;
|
||||
@ -18,8 +17,7 @@ class OauthRefreshTokenCest {
|
||||
$this->route = new OauthRoute($I);
|
||||
}
|
||||
|
||||
public function testRefreshToken(FunctionalTester $I, Scenario $scenario) {
|
||||
$I = new OauthSteps($scenario);
|
||||
public function testRefreshToken(OauthSteps $I) {
|
||||
$refreshToken = $I->getRefreshToken();
|
||||
$this->route->issueToken($this->buildParams(
|
||||
$refreshToken,
|
||||
@ -36,8 +34,7 @@ class OauthRefreshTokenCest {
|
||||
$I->canSeeResponseJsonMatchesJsonPath('$.expires_in');
|
||||
}
|
||||
|
||||
public function testRefreshTokenWithSameScopes(FunctionalTester $I, Scenario $scenario) {
|
||||
$I = new OauthSteps($scenario);
|
||||
public function testRefreshTokenWithSameScopes(OauthSteps $I) {
|
||||
$refreshToken = $I->getRefreshToken();
|
||||
$this->route->issueToken($this->buildParams(
|
||||
$refreshToken,
|
||||
@ -55,8 +52,7 @@ class OauthRefreshTokenCest {
|
||||
$I->canSeeResponseJsonMatchesJsonPath('$.expires_in');
|
||||
}
|
||||
|
||||
public function testRefreshTokenWithNewScopes(FunctionalTester $I, Scenario $scenario) {
|
||||
$I = new OauthSteps($scenario);
|
||||
public function testRefreshTokenWithNewScopes(OauthSteps $I) {
|
||||
$refreshToken = $I->getRefreshToken();
|
||||
$this->route->issueToken($this->buildParams(
|
||||
$refreshToken,
|
||||
|
@ -1,23 +0,0 @@
|
||||
<?php
|
||||
namespace tests\codeception\api\functional\_steps;
|
||||
|
||||
use tests\codeception\api\_pages\LoginRoute;
|
||||
use tests\codeception\api\FunctionalTester;
|
||||
|
||||
class AccountSteps extends FunctionalTester {
|
||||
|
||||
public function loggedInAsActiveAccount() {
|
||||
$I = $this;
|
||||
$route = new LoginRoute($I);
|
||||
$route->login('Admin', 'password_0');
|
||||
$I->canSeeResponseIsJson();
|
||||
$I->canSeeResponseJsonMatchesJsonPath('$.jwt');
|
||||
$jwt = $I->grabDataFromResponseByJsonPath('$.jwt')[0];
|
||||
$I->amBearerAuthenticated($jwt);
|
||||
}
|
||||
|
||||
public function notLoggedIn() {
|
||||
$this->haveHttpHeader('Authorization', null);
|
||||
}
|
||||
|
||||
}
|
@ -3,7 +3,7 @@ namespace tests\codeception\api\functional\_steps;
|
||||
|
||||
use tests\codeception\api\_pages\OauthRoute;
|
||||
|
||||
class OauthSteps extends AccountSteps {
|
||||
class OauthSteps extends \tests\codeception\api\FunctionalTester {
|
||||
|
||||
public function getAuthCode($online = true) {
|
||||
// TODO: по идее можно напрямую сделать зпись в базу, что ускорит процесс тестирования
|
||||
|
@ -71,9 +71,10 @@ class ChangePasswordFormTest extends DbTestCase {
|
||||
'newRePassword' => 'my-new-password',
|
||||
]);
|
||||
$this->specify('successfully change password with modern hash strategy', function() use ($model, $account) {
|
||||
$callTime = time();
|
||||
expect('form should return true', $model->changePassword())->true();
|
||||
expect('new password should be successfully stored into account', $account->validatePassword('my-new-password'))->true();
|
||||
expect('password change time updated', $account->password_changed_at)->greaterOrEquals(time() - 2);
|
||||
expect('password change time updated', $account->password_changed_at)->greaterOrEquals($callTime);
|
||||
});
|
||||
|
||||
/** @var Account $account */
|
||||
|
3
tests/codeception/common/.gitignore
vendored
3
tests/codeception/common/.gitignore
vendored
@ -1,3 +1,2 @@
|
||||
# these files are auto generated by codeception build
|
||||
/unit/UnitTester.php
|
||||
/functional/FunctionalTester.php
|
||||
_support/_generated
|
||||
|
25
tests/codeception/common/_support/UnitTester.php
Normal file
25
tests/codeception/common/_support/UnitTester.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace tests\codeception\common;
|
||||
|
||||
/**
|
||||
* Inherited Methods
|
||||
* @method void wantToTest($text)
|
||||
* @method void wantTo($text)
|
||||
* @method void execute($callable)
|
||||
* @method void expectTo($prediction)
|
||||
* @method void expect($prediction)
|
||||
* @method void amGoingTo($argumentation)
|
||||
* @method void am($role)
|
||||
* @method void lookForwardTo($achieveValue)
|
||||
* @method void comment($description)
|
||||
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
|
||||
*
|
||||
* @SuppressWarnings(PHPMD)
|
||||
*/
|
||||
class UnitTester extends \Codeception\Actor {
|
||||
use _generated\UnitTesterActions;
|
||||
|
||||
/**
|
||||
* Define custom actions here
|
||||
*/
|
||||
}
|
2
tests/codeception/console/.gitignore
vendored
2
tests/codeception/console/.gitignore
vendored
@ -1,2 +1,2 @@
|
||||
# these files are auto generated by codeception build
|
||||
/unit/UnitTester.php
|
||||
_support/_generated
|
||||
|
26
tests/codeception/console/_support/UnitTester.php
Normal file
26
tests/codeception/console/_support/UnitTester.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace tests\codeception\console;
|
||||
|
||||
/**
|
||||
* Inherited Methods
|
||||
* @method void wantToTest($text)
|
||||
* @method void wantTo($text)
|
||||
* @method void execute($callable)
|
||||
* @method void expectTo($prediction)
|
||||
* @method void expect($prediction)
|
||||
* @method void amGoingTo($argumentation)
|
||||
* @method void am($role)
|
||||
* @method void lookForwardTo($achieveValue)
|
||||
* @method void comment($description)
|
||||
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
|
||||
*
|
||||
* @SuppressWarnings(PHPMD)
|
||||
*/
|
||||
class UnitTester extends \Codeception\Actor
|
||||
{
|
||||
use _generated\UnitTesterActions;
|
||||
|
||||
/**
|
||||
* Define custom actions here
|
||||
*/
|
||||
}
|
Loading…
Reference in New Issue
Block a user