Implemented PHP-CS-Fixer support

This commit is contained in:
ErickSkrauch
2018-04-17 23:47:25 +03:00
parent bfdcaf2233
commit 02ea7346a8
115 changed files with 883 additions and 363 deletions

View File

@@ -17,7 +17,7 @@ require_once __DIR__ . '/../../../api/config/bootstrap.php';
// the entry script file path for functional tests
$_SERVER['SCRIPT_FILENAME'] = API_ENTRY_FILE;
$_SERVER['SCRIPT_NAME'] = API_ENTRY_URL;
$_SERVER['SERVER_NAME'] = parse_url(Configuration::config()['config']['test_entry_url'], PHP_URL_HOST);
$_SERVER['SERVER_PORT'] = parse_url(Configuration::config()['config']['test_entry_url'], PHP_URL_PORT) ?: '80';
$_SERVER['SERVER_NAME'] = parse_url(Configuration::config()['config']['test_entry_url'], PHP_URL_HOST);
$_SERVER['SERVER_PORT'] = parse_url(Configuration::config()['config']['test_entry_url'], PHP_URL_PORT) ?: '80';
Yii::setAlias('@tests', dirname(__DIR__, 2));

View File

@@ -16,11 +16,11 @@ namespace tests\codeception\api;
*
* @SuppressWarnings(PHPMD)
*/
class UnitTester extends \Codeception\Actor
{
class UnitTester extends \Codeception\Actor {
use _generated\UnitTesterActions;
/**
* Define custom actions here
*/
/**
* Define custom actions here
*/
}

View File

@@ -35,7 +35,7 @@ class SessionServerSteps extends FunctionalTester {
return [$username, $serverId];
}
public function canSeeValidTexturesResponse($expectedUsername, $expectedUuid) {
$this->seeResponseIsJson();
$this->canSeeResponseContainsJson([

View File

@@ -1,8 +1,8 @@
<?php
namespace tests\codeception\api\functional\authserver;
use tests\codeception\api\_pages\AuthserverRoute;
use Ramsey\Uuid\Uuid;
use tests\codeception\api\_pages\AuthserverRoute;
use tests\codeception\api\FunctionalTester;
class AuthorizationCest {

View File

@@ -64,9 +64,10 @@ class UsernamesToUuidsCest {
public function passTooManyUsernames(FunctionalTester $I) {
$I->wantTo('get specific response when pass too many usernames');
$usernames = [];
for($i = 0; $i < 150; $i++) {
for ($i = 0; $i < 150; $i++) {
$usernames[] = random_bytes(10);
}
$this->route->uuidsByUsernames($usernames);
$I->canSeeResponseCodeIs(400);
$I->canSeeResponseIsJson();

View File

@@ -3,13 +3,18 @@ namespace tests\codeception\api\unit;
use Mockery;
class TestCase extends \Codeception\Test\Unit {
class TestCase extends \Codeception\Test\Unit {
/**
* @var \tests\codeception\api\UnitTester
*/
protected $tester;
protected function tearDown() {
parent::tearDown();
Mockery::close();
}
/**
* Список фикстур, что будут загружены перед тестом, но после зачистки базы данных
*
@@ -21,9 +26,4 @@ class TestCase extends \Codeception\Test\Unit {
return [];
}
protected function tearDown() {
parent::tearDown();
Mockery::close();
}
}

View File

@@ -1,9 +1,9 @@
<?php
namespace codeception\api\unit\components\User;
use api\components\User\AuthenticationResult;
use api\components\User\Component;
use api\components\User\Identity;
use api\components\User\AuthenticationResult;
use common\models\Account;
use common\models\AccountSession;
use Emarref\Jwt\Claim;

View File

@@ -32,7 +32,7 @@ class LoginFormTest extends TestCase {
}
public function testValidateLogin() {
$this->specify('error.login_not_exist if login not exists', function () {
$this->specify('error.login_not_exist if login not exists', function() {
$model = $this->createModel([
'login' => 'mr-test',
'account' => null,
@@ -41,7 +41,7 @@ class LoginFormTest extends TestCase {
$this->assertEquals(['error.login_not_exist'], $model->getErrors('login'));
});
$this->specify('no errors if login exists', function () {
$this->specify('no errors if login exists', function() {
$model = $this->createModel([
'login' => 'mr-test',
'account' => new Account(),
@@ -52,7 +52,7 @@ class LoginFormTest extends TestCase {
}
public function testValidatePassword() {
$this->specify('error.password_incorrect if password invalid', function () {
$this->specify('error.password_incorrect if password invalid', function() {
$model = $this->createModel([
'password' => '87654321',
'account' => new Account(['password' => '12345678']),
@@ -61,7 +61,7 @@ class LoginFormTest extends TestCase {
$this->assertEquals(['error.password_incorrect'], $model->getErrors('password'));
});
$this->specify('no errors if password valid', function () {
$this->specify('no errors if password valid', function() {
$model = $this->createModel([
'password' => '12345678',
'account' => new Account(['password' => '12345678']),
@@ -100,7 +100,7 @@ class LoginFormTest extends TestCase {
}
public function testValidateActivity() {
$this->specify('error.account_not_activated if account in not activated state', function () {
$this->specify('error.account_not_activated if account in not activated state', function() {
$model = $this->createModel([
'account' => new Account(['status' => Account::STATUS_REGISTERED]),
]);
@@ -108,7 +108,7 @@ class LoginFormTest extends TestCase {
$this->assertEquals(['error.account_not_activated'], $model->getErrors('login'));
});
$this->specify('error.account_banned if account has banned status', function () {
$this->specify('error.account_banned if account has banned status', function() {
$model = $this->createModel([
'account' => new Account(['status' => Account::STATUS_BANNED]),
]);
@@ -116,7 +116,7 @@ class LoginFormTest extends TestCase {
$this->assertEquals(['error.account_banned'], $model->getErrors('login'));
});
$this->specify('no errors if account active', function () {
$this->specify('no errors if account active', function() {
$model = $this->createModel([
'account' => new Account(['status' => Account::STATUS_ACTIVE]),
]);

View File

@@ -13,7 +13,7 @@ class LogoutFormTest extends TestCase {
use Specify;
public function testValidateLogout() {
$this->specify('No actions if active session is not exists', function () {
$this->specify('No actions if active session is not exists', function() {
$userComp = $this
->getMockBuilder(Component::class)
->setConstructorArgs([$this->getComponentArgs()])
@@ -30,7 +30,7 @@ class LogoutFormTest extends TestCase {
expect($model->logout())->true();
});
$this->specify('if active session is presented, then delete should be called', function () {
$this->specify('if active session is presented, then delete should be called', function() {
$session = $this
->getMockBuilder(AccountSession::class)
->setMethods(['delete'])

View File

@@ -1,8 +1,8 @@
<?php
namespace tests\codeception\api\unit\modules\internal\models;
use api\modules\internal\helpers\Error as E;
use api\modules\accounts\models\BanAccountForm;
use api\modules\internal\helpers\Error as E;
use common\models\Account;
use tests\codeception\api\unit\TestCase;

View File

@@ -1,8 +1,8 @@
<?php
namespace tests\codeception\api\unit\modules\internal\models;
use api\modules\internal\helpers\Error as E;
use api\modules\accounts\models\PardonAccountForm;
use api\modules\internal\helpers\Error as E;
use common\models\Account;
use tests\codeception\api\unit\TestCase;

View File

@@ -55,7 +55,6 @@ class OauthClientFormTest extends TestCase {
$form->shouldReceive('isClientExists')->andReturn(false);
$request = new class implements OauthClientTypeForm {
public function load($data): bool {
return true;
}
@@ -72,7 +71,6 @@ class OauthClientFormTest extends TestCase {
$client->name = 'New name';
$client->description = 'New description.';
}
};
$this->assertTrue($form->save($request));

View File

@@ -25,7 +25,7 @@ class RateLimiterTest extends TestCase {
/** @var RateLimiter|\PHPUnit_Framework_MockObject_MockObject $filter */
$filter = $this->getMockBuilder(RateLimiter::class)
->setConstructorArgs([[
'authserverDomain' => Yii::$app->params['authserverHost']
'authserverDomain' => Yii::$app->params['authserverHost'],
]])
->setMethods(['getServer'])
->getMock();
@@ -58,7 +58,7 @@ class RateLimiterTest extends TestCase {
->will($this->returnValue('http://authserver.ely.by'));
$filter = new RateLimiter([
'authserverDomain' => Yii::$app->params['authserverHost']
'authserverDomain' => Yii::$app->params['authserverHost'],
]);
$filter->checkRateLimit(null, $request, null, null);
}

View File

@@ -2,11 +2,11 @@
namespace codeception\api\unit\validators;
use api\validators\PasswordRequiredValidator;
use common\helpers\Error as E;
use common\models\Account;
use common\rbac\Permissions as P;
use tests\codeception\api\unit\TestCase;
use tests\codeception\common\_support\ProtectedCaller;
use common\helpers\Error as E;
use yii\web\User;
class PasswordRequiredValidatorTest extends TestCase {