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 {

View File

@@ -1,7 +1,6 @@
<?php
namespace tests\codeception\common\_support;
use Codeception\Module;
use ReflectionClass;
trait ProtectedCaller {

View File

@@ -19,7 +19,8 @@ namespace tests\codeception\common;
class UnitTester extends \Codeception\Actor {
use _generated\UnitTesterActions;
/**
* Define custom actions here
*/
/**
* Define custom actions here
*/
}

View File

@@ -79,7 +79,7 @@ class Helper extends Module {
return $this->getYii2()->grabComponent($component);
}
private function getYii2() : Yii2 {
private function getYii2(): Yii2 {
$yii2 = $this->getModule('Yii2');
if (!$yii2 instanceof Yii2) {
throw new ModuleException($this, 'Yii2 module must be configured');

View File

@@ -40,13 +40,13 @@ class TestComponent extends Component {
* @param string|null $exchangeName
* @return \PhpAmqpLib\Message\AMQPMessage[]
*/
public function getSentMessages(string $exchangeName = null) : array {
public function getSentMessages(string $exchangeName = null): array {
if ($exchangeName !== null) {
return $this->sentMessages[$exchangeName] ?? [];
}
$messages = [];
foreach($this->sentMessages as $exchangeGroup) {
foreach ($this->sentMessages as $exchangeGroup) {
foreach ($exchangeGroup as $message) {
$messages[] = $message;
}

View File

@@ -8,6 +8,11 @@ class Queue extends BaseQueue {
private $messages = [];
public function __set($name, $value) {
// Yii2 components may contains some configuration
// But we just ignore it for this mock component
}
public function push($job) {
$this->messages[] = $job;
}
@@ -24,9 +29,4 @@ class Queue extends BaseQueue {
// This function is abstract, but will be not called
}
public function __set($name, $value) {
// Yii2 components may contains some configuration
// But we just ignore it for this mock component
}
}

View File

@@ -3,13 +3,18 @@ namespace tests\codeception\common\unit;
use Mockery;
class TestCase extends \Codeception\Test\Unit {
class TestCase extends \Codeception\Test\Unit {
/**
* @var \tests\codeception\common\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

@@ -14,17 +14,17 @@ class PrimaryKeyValueBehaviorTest extends TestCase {
$model = new DummyModel();
/** @var PrimaryKeyValueBehavior|\PHPUnit_Framework_MockObject_MockObject $behavior */
$behavior = $this->getMockBuilder(PrimaryKeyValueBehavior::class)
->setMethods(['isValueExists'])
->setConstructorArgs([[
'value' => function() {
return 'mock';
},
]])
->getMock();
->setMethods(['isValueExists'])
->setConstructorArgs([[
'value' => function() {
return 'mock';
},
]])
->getMock();
$behavior->expects($this->once())
->method('isValueExists')
->will($this->returnValue(false));
->method('isValueExists')
->will($this->returnValue(false));
$model->attachBehavior('primary-key-value-behavior', $behavior);
$behavior->setPrimaryKeyValue();
@@ -44,12 +44,12 @@ class PrimaryKeyValueBehaviorTest extends TestCase {
->getMock();
$behavior->expects($this->exactly(3))
->method('generateValue')
->will($this->onConsecutiveCalls('1', '2', '3'));
->method('generateValue')
->will($this->onConsecutiveCalls('1', '2', '3'));
$behavior->expects($this->exactly(3))
->method('isValueExists')
->will($this->onConsecutiveCalls(true, true, false));
->method('isValueExists')
->will($this->onConsecutiveCalls(true, true, false));
$model->attachBehavior('primary-key-value-behavior', $behavior);
$behavior->setPrimaryKeyValue();

View File

@@ -115,7 +115,7 @@ class EmailValidatorTest extends TestCase {
* @param string $fieldValue
* @return Model
*/
private function createModel(string $fieldValue) : Model {
private function createModel(string $fieldValue): Model {
$class = new class extends Model {
public $field;
};

View File

@@ -50,21 +50,22 @@ class UsernameValidatorTest extends TestCase {
$this->assertNotEquals(['error.username_too_long'], $model->getErrors('field'));
}
// TODO: rewrite this test with @provider usage
public function testValidateAttributePattern() {
$shouldBeValid = [
'русский_ник', 'русский_ник_на_грани!', 'numbers1132', '*__*-Stars-*__*', '1-_.!$%^&*()[]',
'[ESP]Эрик', 'Свят_помидор;', роблена_ў_беларусі:)',
];
foreach($shouldBeValid as $nickname) {
foreach ($shouldBeValid as $nickname) {
$model = $this->createModel($nickname);
$this->validator->validateAttribute($model, 'field');
$this->assertNotEquals(['error.username_invalid'], $model->getErrors('field'));
}
$shouldBeInvalid = [
'nick@name', 'spaced nick', 'im#hashed', 'quest?ion'
'nick@name', 'spaced nick', 'im#hashed', 'quest?ion',
];
foreach($shouldBeInvalid as $nickname) {
foreach ($shouldBeInvalid as $nickname) {
$model = $this->createModel($nickname);
$this->validator->validateAttribute($model, 'field');
$this->assertEquals(['error.username_invalid'], $model->getErrors('field'));
@@ -100,7 +101,7 @@ class UsernameValidatorTest extends TestCase {
* @param string $fieldValue
* @return Model
*/
private function createModel(string $fieldValue) : Model {
private function createModel(string $fieldValue): Model {
$class = new class extends Model {
public $field;
};

View File

@@ -16,11 +16,11 @@ namespace tests\codeception\console;
*
* @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

@@ -11,6 +11,11 @@ class TestCase extends Unit {
*/
protected $tester;
protected function tearDown() {
parent::tearDown();
Mockery::close();
}
/**
* Список фикстур, что будут загружены перед тестом, но после зачистки базы данных
*
@@ -22,9 +27,4 @@ class TestCase extends Unit {
return [];
}
protected function tearDown() {
parent::tearDown();
Mockery::close();
}
}

View File

@@ -49,9 +49,9 @@ class AccountQueueControllerTest extends TestCase {
->willReturnCallback(function() {
if ($this->expectedResponse === false) {
throw new NoContentException();
} else {
return $this->expectedResponse;
}
return $this->expectedResponse;
});
$controller