From b20825a051d9d35300da5bbc0fd195091a0d7dd9 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Tue, 26 Feb 2019 02:26:02 +0300 Subject: [PATCH] Update ely/php-code-style and run updated CS fixer --- .php_cs.dist | 5 +- api/components/User/IdentityInterface.php | 2 +- .../accounts/models/AcceptRulesForm.php | 2 +- .../authserver/models/RefreshTokenForm.php | 4 +- api/tests/_bootstrap.php | 6 +- api/tests/_pages/OauthRoute.php | 6 +- api/tests/_support/FunctionalTester.php | 2 +- .../functional/_steps/SessionServerSteps.php | 4 +- .../sessionserver/HasJoinedCest.php | 2 +- .../sessionserver/HasJoinedLegacyCest.php | 2 +- .../components/ReCaptcha/ValidatorTest.php | 4 +- .../unit/components/User/ComponentTest.php | 48 ++++++++-------- .../User/JwtAuthenticationResultTest.php | 12 ++-- api/tests/unit/models/JwtIdentityTest.php | 4 +- .../authentication/ConfirmEmailFormTest.php | 2 +- .../authentication/ForgotPasswordFormTest.php | 8 +-- .../models/authentication/LoginFormTest.php | 16 +++--- .../authentication/RefreshTokenFormTest.php | 2 +- .../authentication/RegistrationFormTest.php | 8 +-- .../RepeatAccountActivationFormTest.php | 2 +- api/tests/unit/models/base/ApiFormTest.php | 2 +- .../accounts/models/AcceptRulesFormTest.php | 2 +- .../accounts/models/ChangeEmailFormTest.php | 2 +- .../models/ChangeLanguageFormTest.php | 2 +- .../models/ChangePasswordFormTest.php | 6 +- .../models/ChangeUsernameFormTest.php | 4 +- .../models/DisableTwoFactorAuthFormTest.php | 2 +- .../models/EnableTwoFactorAuthFormTest.php | 2 +- .../models/SendEmailVerificationFormTest.php | 2 +- .../SendNewEmailVerificationFormTest.php | 4 +- .../accounts/models/TwoFactorAuthInfoTest.php | 2 +- .../models/AuthenticationFormTest.php | 10 ++-- .../modules/internal/models/BanFormTest.php | 4 +- .../internal/models/PardonFormTest.php | 4 +- .../oauth/models/OauthClientFormTest.php | 4 +- api/tests/unit/request/RequestParserTest.php | 10 ++-- api/tests/unit/traits/AccountFinderTest.php | 4 +- .../EmailActivationKeyValidatorTest.php | 14 ++--- .../PasswordRequiredValidatorTest.php | 4 +- .../unit/validators/TotpValidatorTest.php | 6 +- api/web/index.php | 4 +- common/behaviors/PrimaryKeyValueBehavior.php | 13 +++-- common/components/Mojang/Api.php | 4 +- common/models/UsernameHistory.php | 2 +- common/tests/_bootstrap.php | 6 +- .../tests/unit/behaviors/DataBehaviorTest.php | 4 +- .../EmailActivationExpirationBehaviorTest.php | 2 +- .../tests/unit/components/Mojang/ApiTest.php | 4 +- .../tests/unit/db/mysql/QueryBuilderTest.php | 2 +- common/tests/unit/emails/TemplateTest.php | 12 ++-- .../unit/emails/TemplateWithRendererTest.php | 12 ++-- .../tests/unit/helpers/StringHelperTest.php | 12 ++-- .../tests/unit/models/AccountSessionTest.php | 4 +- common/tests/unit/models/AccountTest.php | 12 ++-- .../unit/tasks/ClearOauthSessionsTest.php | 2 +- .../tests/unit/tasks/DeliveryWebHookTest.php | 4 +- .../unit/tasks/PullMojangUsernameTest.php | 2 +- .../unit/validators/EmailValidatorTest.php | 28 +++++----- .../MinecraftServerAddressValidatorTest.php | 19 ++++--- .../unit/validators/UsernameValidatorTest.php | 26 ++++----- .../unit/validators/UuidValidatorTest.php | 8 +-- composer.json | 3 +- composer.lock | 56 ++++++++----------- ...2_200114_migrate_to_utf8md4_unicode_ci.php | 8 +-- console/tests/_bootstrap.php | 6 +- .../controllers/CleanupControllerTest.php | 12 ++-- yii | 4 +- 67 files changed, 250 insertions(+), 252 deletions(-) diff --git a/.php_cs.dist b/.php_cs.dist index 2fca0ef..4acb35a 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -8,9 +8,8 @@ $finder = \PhpCsFixer\Finder::create() ->notPath('common/mail/layouts') ->notPath('/.*\/runtime/') ->notPath('autocompletion.php') - ->notPath('tests/codeception/_output') - ->notPath('/tests\/codeception\/.*\/_output/') - ->notPath('/tests\/codeception\/.*\/_support\/_generated/') + ->notPath('/.*\/tests\/_output/') + ->notPath('/.*\/tests\/_support\/_generated/') ->name('yii'); return \Ely\CS\Config::create() diff --git a/api/components/User/IdentityInterface.php b/api/components/User/IdentityInterface.php index f9f589f..1228483 100644 --- a/api/components/User/IdentityInterface.php +++ b/api/components/User/IdentityInterface.php @@ -12,7 +12,7 @@ interface IdentityInterface extends \yii\web\IdentityInterface { * @throws \yii\web\UnauthorizedHttpException * @return IdentityInterface */ - public static function findIdentityByAccessToken($token, $type = null): IdentityInterface; + public static function findIdentityByAccessToken($token, $type = null): self; /** * Этот метод используется для получения токена, к которому привязаны права. diff --git a/api/modules/accounts/models/AcceptRulesForm.php b/api/modules/accounts/models/AcceptRulesForm.php index 49ec85a..1ff9842 100644 --- a/api/modules/accounts/models/AcceptRulesForm.php +++ b/api/modules/accounts/models/AcceptRulesForm.php @@ -3,7 +3,7 @@ namespace api\modules\accounts\models; use api\aop\annotations\CollectModelMetrics; use yii\base\ErrorException; -use const \common\LATEST_RULES_VERSION; +use const common\LATEST_RULES_VERSION; class AcceptRulesForm extends AccountActionForm { diff --git a/api/modules/authserver/models/RefreshTokenForm.php b/api/modules/authserver/models/RefreshTokenForm.php index 2deb3b1..282cc18 100644 --- a/api/modules/authserver/models/RefreshTokenForm.php +++ b/api/modules/authserver/models/RefreshTokenForm.php @@ -42,9 +42,7 @@ class RefreshTokenForm extends ApiForm { $accessToken->refreshPrimaryKeyValue(); $accessToken->update(); - $dataModel = new AuthenticateData($accessToken); - - return $dataModel; + return new AuthenticateData($accessToken); } } diff --git a/api/tests/_bootstrap.php b/api/tests/_bootstrap.php index 156889d..e919416 100644 --- a/api/tests/_bootstrap.php +++ b/api/tests/_bootstrap.php @@ -1,8 +1,8 @@ getActor()->sendPOST("/api/v1/oauth2/$clientId/reset" . ($regenerateSecret ? '?regenerateSecret' : '')); + $this->getActor()->sendPOST("/api/v1/oauth2/{$clientId}/reset" . ($regenerateSecret ? '?regenerateSecret' : '')); } public function getClient(string $clientId): void { - $this->getActor()->sendGET("/api/v1/oauth2/$clientId"); + $this->getActor()->sendGET("/api/v1/oauth2/{$clientId}"); } public function getPerAccount(int $accountId): void { - $this->getActor()->sendGET("/api/v1/accounts/$accountId/oauth2/clients"); + $this->getActor()->sendGET("/api/v1/accounts/{$accountId}/oauth2/clients"); } } diff --git a/api/tests/_support/FunctionalTester.php b/api/tests/_support/FunctionalTester.php index 45399cd..d39a6a2 100644 --- a/api/tests/_support/FunctionalTester.php +++ b/api/tests/_support/FunctionalTester.php @@ -16,7 +16,7 @@ class FunctionalTester extends Actor { /** @var Account $account */ $account = Account::findOne(['username' => $asUsername]); if ($account === null) { - throw new InvalidArgumentException("Cannot find account for username \"$asUsername\""); + throw new InvalidArgumentException("Cannot find account for username \"{$asUsername}\""); } $result = Yii::$app->user->createJwtAuthenticationToken($account, false); diff --git a/api/tests/functional/_steps/SessionServerSteps.php b/api/tests/functional/_steps/SessionServerSteps.php index 503320c..65bd9c9 100644 --- a/api/tests/functional/_steps/SessionServerSteps.php +++ b/api/tests/functional/_steps/SessionServerSteps.php @@ -54,8 +54,8 @@ class SessionServerSteps extends FunctionalTester { $decoded = json_decode(base64_decode($value), true); $this->assertArrayHasKey('timestamp', $decoded); $this->assertArrayHasKey('textures', $decoded); - $this->assertEquals($expectedUuid, $decoded['profileId']); - $this->assertEquals($expectedUsername, $decoded['profileName']); + $this->assertSame($expectedUuid, $decoded['profileId']); + $this->assertSame($expectedUsername, $decoded['profileName']); $this->assertTrue($decoded['ely']); $textures = $decoded['textures']; $this->assertArrayHasKey('SKIN', $textures); diff --git a/api/tests/functional/sessionserver/HasJoinedCest.php b/api/tests/functional/sessionserver/HasJoinedCest.php index 0bb3d1c..adfe620 100644 --- a/api/tests/functional/sessionserver/HasJoinedCest.php +++ b/api/tests/functional/sessionserver/HasJoinedCest.php @@ -19,7 +19,7 @@ class HasJoinedCest { public function hasJoined(SessionServerSteps $I) { $I->wantTo('check hasJoined user to some server'); - list($username, $serverId) = $I->amJoined(); + [$username, $serverId] = $I->amJoined(); $this->route->hasJoined([ 'username' => $username, diff --git a/api/tests/functional/sessionserver/HasJoinedLegacyCest.php b/api/tests/functional/sessionserver/HasJoinedLegacyCest.php index 7f7d1d6..de0a852 100644 --- a/api/tests/functional/sessionserver/HasJoinedLegacyCest.php +++ b/api/tests/functional/sessionserver/HasJoinedLegacyCest.php @@ -19,7 +19,7 @@ class HasJoinedLegacyCest { public function hasJoined(SessionServerSteps $I) { $I->wantTo('test hasJoined user to some server by legacy version'); - list($username, $serverId) = $I->amJoined(true); + [$username, $serverId] = $I->amJoined(true); $this->route->hasJoinedLegacy([ 'user' => $username, diff --git a/api/tests/unit/components/ReCaptcha/ValidatorTest.php b/api/tests/unit/components/ReCaptcha/ValidatorTest.php index dc9fc08..f122d09 100644 --- a/api/tests/unit/components/ReCaptcha/ValidatorTest.php +++ b/api/tests/unit/components/ReCaptcha/ValidatorTest.php @@ -14,7 +14,7 @@ class ValidatorTest extends TestCase { public function testValidateEmptyValue() { $validator = new Validator(mock(ClientInterface::class)); $this->assertFalse($validator->validate('', $error)); - $this->assertEquals('error.captcha_required', $error, 'Get error.captcha_required, if passed empty value'); + $this->assertSame('error.captcha_required', $error, 'Get error.captcha_required, if passed empty value'); } public function testValidateInvalidValue() { @@ -28,7 +28,7 @@ class ValidatorTest extends TestCase { $validator = new Validator($mockClient); $this->assertFalse($validator->validate('12341234', $error)); - $this->assertEquals('error.captcha_invalid', $error, 'Get error.captcha_invalid, if passed wrong value'); + $this->assertSame('error.captcha_invalid', $error, 'Get error.captcha_invalid, if passed wrong value'); } public function testValidateWithNetworkTroubles() { diff --git a/api/tests/unit/components/User/ComponentTest.php b/api/tests/unit/components/User/ComponentTest.php index 6998df3..8448bbe 100644 --- a/api/tests/unit/components/User/ComponentTest.php +++ b/api/tests/unit/components/User/ComponentTest.php @@ -45,17 +45,17 @@ class ComponentTest extends TestCase { $result = $this->component->createJwtAuthenticationToken($account, false); $this->assertInstanceOf(AuthenticationResult::class, $result); $this->assertNull($result->getSession()); - $this->assertEquals($account, $result->getAccount()); + $this->assertSame($account, $result->getAccount()); $payloads = (new Jwt())->deserialize($result->getJwt())->getPayload(); /** @noinspection NullPointerExceptionInspection */ - $this->assertEquals(time(), $payloads->findClaimByName(Claim\IssuedAt::NAME)->getValue(), '', 3); + $this->assertEqualsWithDelta(time(), $payloads->findClaimByName(Claim\IssuedAt::NAME)->getValue(), 3); /** @noinspection SummerTimeUnsafeTimeManipulationInspection */ /** @noinspection NullPointerExceptionInspection */ - $this->assertEquals(time() + 60 * 60 * 24 * 7, $payloads->findClaimByName('exp')->getValue(), '', 3); + $this->assertEqualsWithDelta(time() + 60 * 60 * 24 * 7, $payloads->findClaimByName('exp')->getValue(), 3); /** @noinspection NullPointerExceptionInspection */ - $this->assertEquals('ely|1', $payloads->findClaimByName('sub')->getValue()); + $this->assertSame('ely|1', $payloads->findClaimByName('sub')->getValue()); /** @noinspection NullPointerExceptionInspection */ - $this->assertEquals('accounts_web_user', $payloads->findClaimByName('ely-scopes')->getValue()); + $this->assertSame('accounts_web_user', $payloads->findClaimByName('ely-scopes')->getValue()); $this->assertNull($payloads->findClaimByName('jti')); /** @var Account $account */ @@ -63,20 +63,20 @@ class ComponentTest extends TestCase { $result = $this->component->createJwtAuthenticationToken($account, true); $this->assertInstanceOf(AuthenticationResult::class, $result); $this->assertInstanceOf(AccountSession::class, $result->getSession()); - $this->assertEquals($account, $result->getAccount()); + $this->assertSame($account, $result->getAccount()); /** @noinspection NullPointerExceptionInspection */ $this->assertTrue($result->getSession()->refresh()); $payloads = (new Jwt())->deserialize($result->getJwt())->getPayload(); /** @noinspection NullPointerExceptionInspection */ - $this->assertEquals(time(), $payloads->findClaimByName(Claim\IssuedAt::NAME)->getValue(), '', 3); + $this->assertEqualsWithDelta(time(), $payloads->findClaimByName(Claim\IssuedAt::NAME)->getValue(), 3); /** @noinspection NullPointerExceptionInspection */ - $this->assertEquals(time() + 3600, $payloads->findClaimByName('exp')->getValue(), '', 3); + $this->assertEqualsWithDelta(time() + 3600, $payloads->findClaimByName('exp')->getValue(), 3); /** @noinspection NullPointerExceptionInspection */ - $this->assertEquals('ely|1', $payloads->findClaimByName('sub')->getValue()); + $this->assertSame('ely|1', $payloads->findClaimByName('sub')->getValue()); /** @noinspection NullPointerExceptionInspection */ - $this->assertEquals('accounts_web_user', $payloads->findClaimByName('ely-scopes')->getValue()); + $this->assertSame('accounts_web_user', $payloads->findClaimByName('ely-scopes')->getValue()); /** @noinspection NullPointerExceptionInspection */ - $this->assertEquals($result->getSession()->id, $payloads->findClaimByName('jti')->getValue()); + $this->assertSame($result->getSession()->id, $payloads->findClaimByName('jti')->getValue()); } public function testRenewJwtAuthenticationToken() { @@ -85,23 +85,22 @@ class ComponentTest extends TestCase { /** @var AccountSession $session */ $session = $this->tester->grabFixture('sessions', 'admin'); $result = $this->component->renewJwtAuthenticationToken($session); - $this->assertInstanceOf(AuthenticationResult::class, $result); - $this->assertEquals($session, $result->getSession()); - $this->assertEquals($session->account_id, $result->getAccount()->id); + $this->assertSame($session, $result->getSession()); + $this->assertSame($session->account_id, $result->getAccount()->id); $session->refresh(); // reload data from db - $this->assertEquals(time(), $session->last_refreshed_at, '', 3); - $this->assertEquals($userIP, $session->getReadableIp()); + $this->assertEqualsWithDelta(time(), $session->last_refreshed_at, 3); + $this->assertSame($userIP, $session->getReadableIp()); $payloads = (new Jwt())->deserialize($result->getJwt())->getPayload(); /** @noinspection NullPointerExceptionInspection */ - $this->assertEquals(time(), $payloads->findClaimByName(Claim\IssuedAt::NAME)->getValue(), '', 3); + $this->assertEqualsWithDelta(time(), $payloads->findClaimByName(Claim\IssuedAt::NAME)->getValue(), 3); /** @noinspection NullPointerExceptionInspection */ - $this->assertEquals(time() + 3600, $payloads->findClaimByName('exp')->getValue(), '', 3); + $this->assertEqualsWithDelta(time() + 3600, $payloads->findClaimByName('exp')->getValue(), 3); /** @noinspection NullPointerExceptionInspection */ - $this->assertEquals('ely|1', $payloads->findClaimByName('sub')->getValue()); + $this->assertSame('ely|1', $payloads->findClaimByName('sub')->getValue()); /** @noinspection NullPointerExceptionInspection */ - $this->assertEquals('accounts_web_user', $payloads->findClaimByName('ely-scopes')->getValue()); + $this->assertSame('accounts_web_user', $payloads->findClaimByName('ely-scopes')->getValue()); /** @noinspection NullPointerExceptionInspection */ - $this->assertEquals($session->id, $payloads->findClaimByName('jti')->getValue(), 'session has not changed'); + $this->assertSame($session->id, $payloads->findClaimByName('jti')->getValue(), 'session has not changed'); } public function testParseToken() { @@ -123,7 +122,6 @@ class ComponentTest extends TestCase { ->getMock(); $component - ->expects($this->any()) ->method('getIsGuest') ->willReturn(false); @@ -132,7 +130,7 @@ class ComponentTest extends TestCase { $session = $component->getActiveSession(); $this->assertInstanceOf(AccountSession::class, $session); /** @noinspection NullPointerExceptionInspection */ - $this->assertEquals($session->id, $result->getSession()->id); + $this->assertSame($session->id, $result->getSession()->id); } public function testTerminateSessions() { @@ -157,8 +155,8 @@ class ComponentTest extends TestCase { $component->terminateSessions($account, Component::KEEP_CURRENT_SESSION); $sessions = $account->getSessions()->all(); - $this->assertEquals(1, count($sessions)); - $this->assertTrue($sessions[0]->id === $session->id); + $this->assertCount(1, $sessions); + $this->assertSame($session->id, $sessions[0]->id); $component->terminateSessions($account); $this->assertEmpty($account->getSessions()->all()); diff --git a/api/tests/unit/components/User/JwtAuthenticationResultTest.php b/api/tests/unit/components/User/JwtAuthenticationResultTest.php index 7e029d4..29c636d 100644 --- a/api/tests/unit/components/User/JwtAuthenticationResultTest.php +++ b/api/tests/unit/components/User/JwtAuthenticationResultTest.php @@ -17,12 +17,12 @@ class JwtAuthenticationResultTest extends TestCase { $account = new Account(); $account->id = 123; $model = new AuthenticationResult($account, '', null); - $this->assertEquals($account, $model->getAccount()); + $this->assertSame($account, $model->getAccount()); } public function testGetJwt() { $model = new AuthenticationResult(new Account(), 'mocked jwt', null); - $this->assertEquals('mocked jwt', $model->getJwt()); + $this->assertSame('mocked jwt', $model->getJwt()); } public function testGetSession() { @@ -32,14 +32,14 @@ class JwtAuthenticationResultTest extends TestCase { $session = new AccountSession(); $session->id = 321; $model = new AuthenticationResult(new Account(), '', $session); - $this->assertEquals($session, $model->getSession()); + $this->assertSame($session, $model->getSession()); } public function testGetAsResponse() { $jwtToken = $this->createJwtToken(time() + 3600); $model = new AuthenticationResult(new Account(), $jwtToken, null); $result = $model->getAsResponse(); - $this->assertEquals($jwtToken, $result['access_token']); + $this->assertSame($jwtToken, $result['access_token']); $this->assertSame(3600, $result['expires_in']); /** @noinspection SummerTimeUnsafeTimeManipulationInspection */ @@ -48,8 +48,8 @@ class JwtAuthenticationResultTest extends TestCase { $session->refresh_token = 'refresh token'; $model = new AuthenticationResult(new Account(), $jwtToken, $session); $result = $model->getAsResponse(); - $this->assertEquals($jwtToken, $result['access_token']); - $this->assertEquals('refresh token', $result['refresh_token']); + $this->assertSame($jwtToken, $result['access_token']); + $this->assertSame('refresh token', $result['refresh_token']); $this->assertSame(86400, $result['expires_in']); } diff --git a/api/tests/unit/models/JwtIdentityTest.php b/api/tests/unit/models/JwtIdentityTest.php index 432f37d..fdeb957 100644 --- a/api/tests/unit/models/JwtIdentityTest.php +++ b/api/tests/unit/models/JwtIdentityTest.php @@ -27,8 +27,8 @@ class JwtIdentityTest extends TestCase { $token = $this->generateToken(); $identity = JwtIdentity::findIdentityByAccessToken($token); $this->assertInstanceOf(IdentityInterface::class, $identity); - $this->assertEquals($token, $identity->getId()); - $this->assertEquals($this->tester->grabFixture('accounts', 'admin')['id'], $identity->getAccount()->id); + $this->assertSame($token, $identity->getId()); + $this->assertSame($this->tester->grabFixture('accounts', 'admin')['id'], $identity->getAccount()->id); } /** diff --git a/api/tests/unit/models/authentication/ConfirmEmailFormTest.php b/api/tests/unit/models/authentication/ConfirmEmailFormTest.php index 534d13e..db808d5 100644 --- a/api/tests/unit/models/authentication/ConfirmEmailFormTest.php +++ b/api/tests/unit/models/authentication/ConfirmEmailFormTest.php @@ -27,7 +27,7 @@ class ConfirmEmailFormTest extends TestCase { $this->assertFalse($activationExists, 'email activation key is not exist'); /** @var Account $account */ $account = Account::findOne($fixture['account_id']); - $this->assertEquals(Account::STATUS_ACTIVE, $account->status, 'user status changed to active'); + $this->assertSame(Account::STATUS_ACTIVE, $account->status, 'user status changed to active'); } private function createModel($key) { diff --git a/api/tests/unit/models/authentication/ForgotPasswordFormTest.php b/api/tests/unit/models/authentication/ForgotPasswordFormTest.php index 1a4caf1..8dc639a 100644 --- a/api/tests/unit/models/authentication/ForgotPasswordFormTest.php +++ b/api/tests/unit/models/authentication/ForgotPasswordFormTest.php @@ -16,7 +16,7 @@ use Yii; class ForgotPasswordFormTest extends TestCase { use Specify; - public function setUp() { + protected function setUp() { parent::setUp(); Yii::$container->set(ReCaptchaValidator::class, new class(mock(ClientInterface::class)) extends ReCaptchaValidator { public function validateValue($value) { @@ -35,7 +35,7 @@ class ForgotPasswordFormTest extends TestCase { public function testValidateLogin() { $model = new ForgotPasswordForm(['login' => 'unexist']); $model->validateLogin('login'); - $this->assertEquals(['error.login_not_exist'], $model->getErrors('login'), 'error.login_not_exist if login is invalid'); + $this->assertSame(['error.login_not_exist'], $model->getErrors('login'), 'error.login_not_exist if login is invalid'); $model = new ForgotPasswordForm(['login' => $this->tester->grabFixture('accounts', 'admin')['username']]); $model->validateLogin('login'); @@ -47,7 +47,7 @@ class ForgotPasswordFormTest extends TestCase { 'login' => $this->tester->grabFixture('accounts', 'not-activated-account')['username'], ]); $model->validateActivity('login'); - $this->assertEquals(['error.account_not_activated'], $model->getErrors('login'), 'expected error if account is not confirmed'); + $this->assertSame(['error.account_not_activated'], $model->getErrors('login'), 'expected error if account is not confirmed'); $model = new ForgotPasswordForm([ 'login' => $this->tester->grabFixture('accounts', 'admin')['username'], @@ -62,7 +62,7 @@ class ForgotPasswordFormTest extends TestCase { 'key' => $this->tester->grabFixture('emailActivations', 'freshPasswordRecovery')['key'], ]); $model->validateFrequency('login'); - $this->assertEquals(['error.recently_sent_message'], $model->getErrors('login'), 'error.account_not_activated if recently was message'); + $this->assertSame(['error.recently_sent_message'], $model->getErrors('login'), 'error.account_not_activated if recently was message'); $model = $this->createModel([ 'login' => $this->tester->grabFixture('accounts', 'admin')['username'], diff --git a/api/tests/unit/models/authentication/LoginFormTest.php b/api/tests/unit/models/authentication/LoginFormTest.php index a5b32d2..d3285fb 100644 --- a/api/tests/unit/models/authentication/LoginFormTest.php +++ b/api/tests/unit/models/authentication/LoginFormTest.php @@ -14,13 +14,13 @@ class LoginFormTest extends TestCase { private $originalRemoteAddr; - public function setUp() { + protected function setUp() { $this->originalRemoteAddr = $_SERVER['REMOTE_ADDR'] ?? null; $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; parent::setUp(); } - public function tearDown() { + protected function tearDown() { parent::tearDown(); $_SERVER['REMOTE_ADDR'] = $this->originalRemoteAddr; } @@ -38,7 +38,7 @@ class LoginFormTest extends TestCase { 'account' => null, ]); $model->validateLogin('login'); - $this->assertEquals(['error.login_not_exist'], $model->getErrors('login')); + $this->assertSame(['error.login_not_exist'], $model->getErrors('login')); }); $this->specify('no errors if login exists', function() { @@ -58,7 +58,7 @@ class LoginFormTest extends TestCase { 'account' => new Account(['password' => '12345678']), ]); $model->validatePassword('password'); - $this->assertEquals(['error.password_incorrect'], $model->getErrors('password')); + $this->assertSame(['error.password_incorrect'], $model->getErrors('password')); }); $this->specify('no errors if password valid', function() { @@ -84,7 +84,7 @@ class LoginFormTest extends TestCase { 'account' => $account, ]); $model->validateTotp('totp'); - $this->assertEquals(['error.totp_incorrect'], $model->getErrors('totp')); + $this->assertSame(['error.totp_incorrect'], $model->getErrors('totp')); }); $totp = TOTP::create($account->otp_secret); @@ -105,7 +105,7 @@ class LoginFormTest extends TestCase { 'account' => new Account(['status' => Account::STATUS_REGISTERED]), ]); $model->validateActivity('login'); - $this->assertEquals(['error.account_not_activated'], $model->getErrors('login')); + $this->assertSame(['error.account_not_activated'], $model->getErrors('login')); }); $this->specify('error.account_banned if account has banned status', function() { @@ -113,7 +113,7 @@ class LoginFormTest extends TestCase { 'account' => new Account(['status' => Account::STATUS_BANNED]), ]); $model->validateActivity('login'); - $this->assertEquals(['error.account_banned'], $model->getErrors('login')); + $this->assertSame(['error.account_banned'], $model->getErrors('login')); }); $this->specify('no errors if account active', function() { @@ -146,7 +146,7 @@ class LoginFormTest extends TestCase { ]); $this->assertInstanceOf(AuthenticationResult::class, $model->login()); $this->assertEmpty($model->getErrors()); - $this->assertEquals( + $this->assertSame( Account::PASS_HASH_STRATEGY_YII2, $model->getAccount()->password_hash_strategy, 'user, that login using account with old pass hash strategy should update it automatically' diff --git a/api/tests/unit/models/authentication/RefreshTokenFormTest.php b/api/tests/unit/models/authentication/RefreshTokenFormTest.php index 16308a4..b4628f1 100644 --- a/api/tests/unit/models/authentication/RefreshTokenFormTest.php +++ b/api/tests/unit/models/authentication/RefreshTokenFormTest.php @@ -26,7 +26,7 @@ class RefreshTokenFormTest extends TestCase { } }; $model->validateRefreshToken(); - $this->assertEquals(['error.refresh_token_not_exist'], $model->getErrors('refresh_token')); + $this->assertSame(['error.refresh_token_not_exist'], $model->getErrors('refresh_token')); }); $this->specify('no errors if token exists', function() { diff --git a/api/tests/unit/models/authentication/RegistrationFormTest.php b/api/tests/unit/models/authentication/RegistrationFormTest.php index f1939d5..cd37cda 100644 --- a/api/tests/unit/models/authentication/RegistrationFormTest.php +++ b/api/tests/unit/models/authentication/RegistrationFormTest.php @@ -20,7 +20,7 @@ use const common\LATEST_RULES_VERSION; class RegistrationFormTest extends TestCase { - public function setUp() { + protected function setUp() { parent::setUp(); $this->mockRequest(); Yii::$container->set(ReCaptchaValidator::class, new class(mock(ClientInterface::class)) extends ReCaptchaValidator { @@ -68,7 +68,7 @@ class RegistrationFormTest extends TestCase { $account = $model->signup(); $this->expectSuccessRegistration($account); - $this->assertEquals('ru', $account->lang, 'lang is set'); + $this->assertSame('ru', $account->lang, 'lang is set'); } public function testSignupWithDefaultLanguage() { @@ -84,7 +84,7 @@ class RegistrationFormTest extends TestCase { $account = $model->signup(); $this->expectSuccessRegistration($account); - $this->assertEquals('en', $account->lang, 'lang is set'); + $this->assertSame('en', $account->lang, 'lang is set'); } /** @@ -95,7 +95,7 @@ class RegistrationFormTest extends TestCase { $this->assertTrue($account->validatePassword('some_password'), 'password should be correct'); $this->assertNotEmpty($account->uuid, 'uuid is set'); $this->assertNotNull($account->registration_ip, 'registration_ip is set'); - $this->assertEquals(LATEST_RULES_VERSION, $account->rules_agreement_version, 'actual rules version is set'); + $this->assertSame(LATEST_RULES_VERSION, $account->rules_agreement_version, 'actual rules version is set'); $this->assertTrue(Account::find()->andWhere([ 'username' => 'some_username', 'email' => 'some_email@example.com', diff --git a/api/tests/unit/models/authentication/RepeatAccountActivationFormTest.php b/api/tests/unit/models/authentication/RepeatAccountActivationFormTest.php index 3a6162b..c70a364 100644 --- a/api/tests/unit/models/authentication/RepeatAccountActivationFormTest.php +++ b/api/tests/unit/models/authentication/RepeatAccountActivationFormTest.php @@ -15,7 +15,7 @@ use Yii; class RepeatAccountActivationFormTest extends TestCase { use Specify; - public function setUp() { + protected function setUp() { parent::setUp(); Yii::$container->set(ReCaptchaValidator::class, new class(mock(ClientInterface::class)) extends ReCaptchaValidator { public function validateValue($value) { diff --git a/api/tests/unit/models/base/ApiFormTest.php b/api/tests/unit/models/base/ApiFormTest.php index 632a1f7..d422692 100644 --- a/api/tests/unit/models/base/ApiFormTest.php +++ b/api/tests/unit/models/base/ApiFormTest.php @@ -9,7 +9,7 @@ class ApiFormTest extends TestCase { public function testLoad() { $model = new DummyApiForm(); $this->assertTrue($model->load(['field' => 'test-data']), 'model successful load data without prefix'); - $this->assertEquals('test-data', $model->field, 'field is set as passed data'); + $this->assertSame('test-data', $model->field, 'field is set as passed data'); } } diff --git a/api/tests/unit/modules/accounts/models/AcceptRulesFormTest.php b/api/tests/unit/modules/accounts/models/AcceptRulesFormTest.php index c354cef..0c5f92f 100644 --- a/api/tests/unit/modules/accounts/models/AcceptRulesFormTest.php +++ b/api/tests/unit/modules/accounts/models/AcceptRulesFormTest.php @@ -16,7 +16,7 @@ class AcceptRulesFormTest extends TestCase { $model = new AcceptRulesForm($account); $this->assertTrue($model->performAction()); - $this->assertEquals(LATEST_RULES_VERSION, $account->rules_agreement_version); + $this->assertSame(LATEST_RULES_VERSION, $account->rules_agreement_version); } } diff --git a/api/tests/unit/modules/accounts/models/ChangeEmailFormTest.php b/api/tests/unit/modules/accounts/models/ChangeEmailFormTest.php index a8f7c14..7106fca 100644 --- a/api/tests/unit/modules/accounts/models/ChangeEmailFormTest.php +++ b/api/tests/unit/modules/accounts/models/ChangeEmailFormTest.php @@ -31,7 +31,7 @@ class ChangeEmailFormTest extends TestCase { ])); /** @noinspection UnserializeExploitsInspection */ $data = unserialize($newEmailConfirmationFixture['_data']); - $this->assertEquals($data['newEmail'], $account->email); + $this->assertSame($data['newEmail'], $account->email); } private function getAccountId() { diff --git a/api/tests/unit/modules/accounts/models/ChangeLanguageFormTest.php b/api/tests/unit/modules/accounts/models/ChangeLanguageFormTest.php index 890aa17..1cb1337 100644 --- a/api/tests/unit/modules/accounts/models/ChangeLanguageFormTest.php +++ b/api/tests/unit/modules/accounts/models/ChangeLanguageFormTest.php @@ -15,7 +15,7 @@ class ChangeLanguageFormTest extends TestCase { $model = new ChangeLanguageForm($account); $model->lang = 'ru'; $this->assertTrue($model->performAction()); - $this->assertEquals('ru', $account->lang); + $this->assertSame('ru', $account->lang); } } diff --git a/api/tests/unit/modules/accounts/models/ChangePasswordFormTest.php b/api/tests/unit/modules/accounts/models/ChangePasswordFormTest.php index 36dc32c..552a185 100644 --- a/api/tests/unit/modules/accounts/models/ChangePasswordFormTest.php +++ b/api/tests/unit/modules/accounts/models/ChangePasswordFormTest.php @@ -22,7 +22,7 @@ class ChangePasswordFormTest extends TestCase { 'newRePassword' => 'another-password', ]); $model->validatePasswordAndRePasswordMatch('newRePassword'); - $this->assertEquals( + $this->assertSame( [E::NEW_RE_PASSWORD_DOES_NOT_MATCH], $model->getErrors('newRePassword'), 'error.rePassword_does_not_match expected if passwords not match' @@ -47,7 +47,7 @@ class ChangePasswordFormTest extends TestCase { 'newRePassword' => 'another-password', ]); $model->validate(); - $this->assertEquals( + $this->assertSame( [E::NEW_RE_PASSWORD_DOES_NOT_MATCH], $model->getErrors('newRePassword'), 'error.rePassword_does_not_match expected even if there are errors on other attributes' @@ -106,7 +106,7 @@ class ChangePasswordFormTest extends TestCase { $this->assertTrue($model->performAction(), 'successfully change password with legacy hash strategy'); $this->assertTrue($account->validatePassword('my-new-password')); $this->assertGreaterThanOrEqual($callTime, $account->password_changed_at); - $this->assertEquals(Account::PASS_HASH_STRATEGY_YII2, $account->password_hash_strategy); + $this->assertSame(Account::PASS_HASH_STRATEGY_YII2, $account->password_hash_strategy); } public function testPerformActionWithLogout() { diff --git a/api/tests/unit/modules/accounts/models/ChangeUsernameFormTest.php b/api/tests/unit/modules/accounts/models/ChangeUsernameFormTest.php index fad9db4..60cc365 100644 --- a/api/tests/unit/modules/accounts/models/ChangeUsernameFormTest.php +++ b/api/tests/unit/modules/accounts/models/ChangeUsernameFormTest.php @@ -24,7 +24,7 @@ class ChangeUsernameFormTest extends TestCase { 'username' => 'my_new_nickname', ]); $this->assertTrue($model->performAction()); - $this->assertEquals('my_new_nickname', Account::findOne($this->getAccountId())->username); + $this->assertSame('my_new_nickname', Account::findOne($this->getAccountId())->username); $this->assertInstanceOf(UsernameHistory::class, UsernameHistory::findOne(['username' => 'my_new_nickname'])); /** @var PullMojangUsername $job */ $job = $this->tester->grabLastQueuedJob(); @@ -56,7 +56,7 @@ class ChangeUsernameFormTest extends TestCase { 'username' => $newUsername, ]); $this->assertTrue($model->performAction()); - $this->assertEquals($newUsername, Account::findOne($this->getAccountId())->username); + $this->assertSame($newUsername, Account::findOne($this->getAccountId())->username); $this->assertInstanceOf( UsernameHistory::class, UsernameHistory::findOne(['username' => $newUsername]), diff --git a/api/tests/unit/modules/accounts/models/DisableTwoFactorAuthFormTest.php b/api/tests/unit/modules/accounts/models/DisableTwoFactorAuthFormTest.php index 618c53d..b2eda1e 100644 --- a/api/tests/unit/modules/accounts/models/DisableTwoFactorAuthFormTest.php +++ b/api/tests/unit/modules/accounts/models/DisableTwoFactorAuthFormTest.php @@ -30,7 +30,7 @@ class DisableTwoFactorAuthFormTest extends TestCase { $account->is_otp_enabled = false; $model = new DisableTwoFactorAuthForm($account); $model->validateOtpEnabled('account'); - $this->assertEquals([E::OTP_NOT_ENABLED], $model->getErrors('account')); + $this->assertSame([E::OTP_NOT_ENABLED], $model->getErrors('account')); $account = new Account(); $account->is_otp_enabled = true; diff --git a/api/tests/unit/modules/accounts/models/EnableTwoFactorAuthFormTest.php b/api/tests/unit/modules/accounts/models/EnableTwoFactorAuthFormTest.php index 4bacfe4..84878ff 100644 --- a/api/tests/unit/modules/accounts/models/EnableTwoFactorAuthFormTest.php +++ b/api/tests/unit/modules/accounts/models/EnableTwoFactorAuthFormTest.php @@ -42,7 +42,7 @@ class EnableTwoFactorAuthFormTest extends TestCase { $account->is_otp_enabled = true; $model = new EnableTwoFactorAuthForm($account); $model->validateOtpDisabled('account'); - $this->assertEquals([E::OTP_ALREADY_ENABLED], $model->getErrors('account')); + $this->assertSame([E::OTP_ALREADY_ENABLED], $model->getErrors('account')); $account = new Account(); $account->is_otp_enabled = false; diff --git a/api/tests/unit/modules/accounts/models/SendEmailVerificationFormTest.php b/api/tests/unit/modules/accounts/models/SendEmailVerificationFormTest.php index 52ed48c..8a9b967 100644 --- a/api/tests/unit/modules/accounts/models/SendEmailVerificationFormTest.php +++ b/api/tests/unit/modules/accounts/models/SendEmailVerificationFormTest.php @@ -25,7 +25,7 @@ class SendEmailVerificationFormTest extends TestCase { $model = new SendEmailVerificationForm($account); $activationModel = $model->createCode(); $this->assertInstanceOf(CurrentEmailConfirmation::class, $activationModel); - $this->assertEquals($account->id, $activationModel->account_id); + $this->assertSame($account->id, $activationModel->account_id); $this->assertNotNull(EmailActivation::findOne($activationModel->key)); } diff --git a/api/tests/unit/modules/accounts/models/SendNewEmailVerificationFormTest.php b/api/tests/unit/modules/accounts/models/SendNewEmailVerificationFormTest.php index 64023c7..529190d 100644 --- a/api/tests/unit/modules/accounts/models/SendNewEmailVerificationFormTest.php +++ b/api/tests/unit/modules/accounts/models/SendNewEmailVerificationFormTest.php @@ -28,8 +28,8 @@ class SendNewEmailVerificationFormTest extends TestCase { $model->email = 'my-new-email@ely.by'; $activationModel = $model->createCode(); $this->assertInstanceOf(NewEmailConfirmation::class, $activationModel); - $this->assertEquals($account->id, $activationModel->account_id); - $this->assertEquals($model->email, $activationModel->newEmail); + $this->assertSame($account->id, $activationModel->account_id); + $this->assertSame($model->email, $activationModel->newEmail); $this->assertNotNull(EmailActivation::findOne($activationModel->key)); } diff --git a/api/tests/unit/modules/accounts/models/TwoFactorAuthInfoTest.php b/api/tests/unit/modules/accounts/models/TwoFactorAuthInfoTest.php index ee5d455..bb78ee1 100644 --- a/api/tests/unit/modules/accounts/models/TwoFactorAuthInfoTest.php +++ b/api/tests/unit/modules/accounts/models/TwoFactorAuthInfoTest.php @@ -41,7 +41,7 @@ class TwoFactorAuthInfoTest extends TestCase { $model = new TwoFactorAuthInfo($account); $result = $model->getCredentials(); - $this->assertEquals('AAAA', $result['secret']); + $this->assertSame('AAAA', $result['secret']); } } diff --git a/api/tests/unit/modules/authserver/models/AuthenticationFormTest.php b/api/tests/unit/modules/authserver/models/AuthenticationFormTest.php index 5395a86..ca8b21f 100644 --- a/api/tests/unit/modules/authserver/models/AuthenticationFormTest.php +++ b/api/tests/unit/modules/authserver/models/AuthenticationFormTest.php @@ -79,7 +79,7 @@ class AuthenticationFormTest extends TestCase { $result = $authForm->authenticate(); $this->assertInstanceOf(AuthenticateData::class, $result); - $this->assertEquals($minecraftAccessKey->access_token, $result->getMinecraftAccessKey()->access_token); + $this->assertSame($minecraftAccessKey->access_token, $result->getMinecraftAccessKey()->access_token); } public function testCreateMinecraftAccessToken() { @@ -90,8 +90,8 @@ class AuthenticationFormTest extends TestCase { /** @var MinecraftAccessKey $result */ $result = $this->callProtected($authForm, 'createMinecraftAccessToken', $account); $this->assertInstanceOf(MinecraftAccessKey::class, $result); - $this->assertEquals($account->id, $result->account_id); - $this->assertEquals($authForm->clientToken, $result->client_token); + $this->assertSame($account->id, $result->account_id); + $this->assertSame($authForm->clientToken, $result->client_token); $this->assertInstanceOf(MinecraftAccessKey::class, MinecraftAccessKey::findOne($result->access_token)); } @@ -104,8 +104,8 @@ class AuthenticationFormTest extends TestCase { /** @var MinecraftAccessKey $result */ $result = $this->callProtected($authForm, 'createMinecraftAccessToken', $account); $this->assertInstanceOf(MinecraftAccessKey::class, $result); - $this->assertEquals($account->id, $result->account_id); - $this->assertEquals($authForm->clientToken, $result->client_token); + $this->assertSame($account->id, $result->account_id); + $this->assertSame($authForm->clientToken, $result->client_token); $this->assertNull(MinecraftAccessKey::findOne($minecraftFixture['access_token'])); $this->assertInstanceOf(MinecraftAccessKey::class, MinecraftAccessKey::findOne($result->access_token)); } diff --git a/api/tests/unit/modules/internal/models/BanFormTest.php b/api/tests/unit/modules/internal/models/BanFormTest.php index 48f53dd..7dd9ea3 100644 --- a/api/tests/unit/modules/internal/models/BanFormTest.php +++ b/api/tests/unit/modules/internal/models/BanFormTest.php @@ -20,7 +20,7 @@ class BanFormTest extends TestCase { $account->status = Account::STATUS_BANNED; $form = new BanAccountForm($account); $form->validateAccountActivity(); - $this->assertEquals([E::ACCOUNT_ALREADY_BANNED], $form->getErrors('account')); + $this->assertSame([E::ACCOUNT_ALREADY_BANNED], $form->getErrors('account')); } public function testBan() { @@ -35,7 +35,7 @@ class BanFormTest extends TestCase { $model = new BanAccountForm($account); $this->assertTrue($model->performAction()); - $this->assertEquals(Account::STATUS_BANNED, $account->status); + $this->assertSame(Account::STATUS_BANNED, $account->status); /** @var ClearAccountSessions $job */ $job = $this->tester->grabLastQueuedJob(); $this->assertInstanceOf(ClearAccountSessions::class, $job); diff --git a/api/tests/unit/modules/internal/models/PardonFormTest.php b/api/tests/unit/modules/internal/models/PardonFormTest.php index 4ae4438..5d469e6 100644 --- a/api/tests/unit/modules/internal/models/PardonFormTest.php +++ b/api/tests/unit/modules/internal/models/PardonFormTest.php @@ -19,7 +19,7 @@ class PardonFormTest extends TestCase { $account->status = Account::STATUS_ACTIVE; $form = new PardonAccountForm($account); $form->validateAccountBanned(); - $this->assertEquals([E::ACCOUNT_NOT_BANNED], $form->getErrors('account')); + $this->assertSame([E::ACCOUNT_NOT_BANNED], $form->getErrors('account')); } public function testPardon() { @@ -35,7 +35,7 @@ class PardonFormTest extends TestCase { $account->status = Account::STATUS_BANNED; $model = new PardonAccountForm($account); $this->assertTrue($model->performAction()); - $this->assertEquals(Account::STATUS_ACTIVE, $account->status); + $this->assertSame(Account::STATUS_ACTIVE, $account->status); } } diff --git a/api/tests/unit/modules/oauth/models/OauthClientFormTest.php b/api/tests/unit/modules/oauth/models/OauthClientFormTest.php index 58820db..de0303f 100644 --- a/api/tests/unit/modules/oauth/models/OauthClientFormTest.php +++ b/api/tests/unit/modules/oauth/models/OauthClientFormTest.php @@ -114,7 +114,7 @@ class OauthClientFormTest extends TestCase { $job = $this->tester->grabLastQueuedJob(); $this->assertInstanceOf(ClearOauthSessions::class, $job); $this->assertSame('mocked-id', $job->clientId); - $this->assertEquals(time(), $job->notSince, '', 2); + $this->assertEqualsWithDelta(time(), $job->notSince, 2); } public function testResetWithSecret() { @@ -132,7 +132,7 @@ class OauthClientFormTest extends TestCase { $job = $this->tester->grabLastQueuedJob(); $this->assertInstanceOf(ClearOauthSessions::class, $job); $this->assertSame('mocked-id', $job->clientId); - $this->assertEquals(time(), $job->notSince, '', 2); + $this->assertEqualsWithDelta(time(), $job->notSince, 2); } } diff --git a/api/tests/unit/request/RequestParserTest.php b/api/tests/unit/request/RequestParserTest.php index 97962b7..0756d86 100644 --- a/api/tests/unit/request/RequestParserTest.php +++ b/api/tests/unit/request/RequestParserTest.php @@ -9,12 +9,12 @@ class RequestParserTest extends TestCase { public function testParse() { $parser = new RequestParser(); $_POST = ['from' => 'post']; - $this->assertEquals(['from' => 'post'], $parser->parse('from=post', '')); - $this->assertEquals(['from' => 'post'], $parser->parse('', '')); + $this->assertSame(['from' => 'post'], $parser->parse('from=post', '')); + $this->assertSame(['from' => 'post'], $parser->parse('', '')); $_POST = []; - $this->assertEquals(['from' => 'json'], $parser->parse('{"from":"json"}', '')); - $this->assertEquals(['from' => 'body'], $parser->parse('from=body', '')); - $this->assertEquals(['onlykey' => ''], $parser->parse('onlykey', '')); + $this->assertSame(['from' => 'json'], $parser->parse('{"from":"json"}', '')); + $this->assertSame(['from' => 'body'], $parser->parse('from=body', '')); + $this->assertSame(['onlykey' => ''], $parser->parse('onlykey', '')); } } diff --git a/api/tests/unit/traits/AccountFinderTest.php b/api/tests/unit/traits/AccountFinderTest.php index 967a4c0..63c4a4c 100644 --- a/api/tests/unit/traits/AccountFinderTest.php +++ b/api/tests/unit/traits/AccountFinderTest.php @@ -33,11 +33,11 @@ class AccountFinderTest extends TestCase { public function testGetLoginAttribute() { $model = new AccountFinderTestTestClass(); $model->login = 'erickskrauch@ely.by'; - $this->assertEquals('email', $model->getLoginAttribute(), 'if login look like email value, then \'email\''); + $this->assertSame('email', $model->getLoginAttribute(), 'if login look like email value, then \'email\''); $model = new AccountFinderTestTestClass(); $model->login = 'erickskrauch'; - $this->assertEquals('username', $model->getLoginAttribute(), 'username in any other case'); + $this->assertSame('username', $model->getLoginAttribute(), 'username in any other case'); } } diff --git a/api/tests/unit/validators/EmailActivationKeyValidatorTest.php b/api/tests/unit/validators/EmailActivationKeyValidatorTest.php index 6467851..f58c323 100644 --- a/api/tests/unit/validators/EmailActivationKeyValidatorTest.php +++ b/api/tests/unit/validators/EmailActivationKeyValidatorTest.php @@ -36,24 +36,24 @@ class EmailActivationKeyValidatorTest extends TestCase { ->willReturnOnConsecutiveCalls(null, $expiredActivation, $validActivation); $validator->validateAttribute($model, 'key'); - $this->assertEquals([E::KEY_REQUIRED], $model->getErrors('key')); + $this->assertSame([E::KEY_REQUIRED], $model->getErrors('key')); $this->assertNull($model->key); $model->clearErrors(); $model->key = 'original value'; $validator->validateAttribute($model, 'key'); - $this->assertEquals([E::KEY_NOT_EXISTS], $model->getErrors('key')); - $this->assertEquals('original value', $model->key); + $this->assertSame([E::KEY_NOT_EXISTS], $model->getErrors('key')); + $this->assertSame('original value', $model->key); $model->clearErrors(); $validator->validateAttribute($model, 'key'); - $this->assertEquals([E::KEY_EXPIRE], $model->getErrors('key')); - $this->assertEquals('original value', $model->key); + $this->assertSame([E::KEY_EXPIRE], $model->getErrors('key')); + $this->assertSame('original value', $model->key); $model->clearErrors(); $validator->validateAttribute($model, 'key'); $this->assertEmpty($model->getErrors('key')); - $this->assertEquals($validActivation, $model->key); + $this->assertSame($validActivation, $model->key); } public function testFindEmailActivationModel() { @@ -64,7 +64,7 @@ class EmailActivationKeyValidatorTest extends TestCase { /** @var EmailActivation $result */ $result = $this->callProtected($model, 'findEmailActivationModel', $key); $this->assertInstanceOf(EmailActivation::class, $result, 'valid key without specifying type must return model'); - $this->assertEquals($key, $result->key); + $this->assertSame($key, $result->key); /** @var EmailActivation $result */ $result = $this->callProtected($model, 'findEmailActivationModel', $key, 0); diff --git a/api/tests/unit/validators/PasswordRequiredValidatorTest.php b/api/tests/unit/validators/PasswordRequiredValidatorTest.php index aaffc40..f60aed6 100644 --- a/api/tests/unit/validators/PasswordRequiredValidatorTest.php +++ b/api/tests/unit/validators/PasswordRequiredValidatorTest.php @@ -17,10 +17,10 @@ class PasswordRequiredValidatorTest extends TestCase { $model = new PasswordRequiredValidator(['account' => $account]); // Get error.password_required if password is empty - $this->assertEquals([E::PASSWORD_REQUIRED, []], $this->callProtected($model, 'validateValue', '')); + $this->assertSame([E::PASSWORD_REQUIRED, []], $this->callProtected($model, 'validateValue', '')); // Get error.password_incorrect if password is incorrect - $this->assertEquals([E::PASSWORD_INCORRECT, []], $this->callProtected($model, 'validateValue', '87654321')); + $this->assertSame([E::PASSWORD_INCORRECT, []], $this->callProtected($model, 'validateValue', '87654321')); // No errors, if password is correct for provided account $this->assertNull($this->callProtected($model, 'validateValue', '12345678')); diff --git a/api/tests/unit/validators/TotpValidatorTest.php b/api/tests/unit/validators/TotpValidatorTest.php index b234892..6baf9e5 100644 --- a/api/tests/unit/validators/TotpValidatorTest.php +++ b/api/tests/unit/validators/TotpValidatorTest.php @@ -19,13 +19,13 @@ class TotpValidatorTest extends TestCase { $validator = new TotpValidator(['account' => $account]); $result = $this->callProtected($validator, 'validateValue', 123456); - $this->assertEquals([E::TOTP_INCORRECT, []], $result); + $this->assertSame([E::TOTP_INCORRECT, []], $result); $result = $this->callProtected($validator, 'validateValue', $controlTotp->now()); $this->assertNull($result); $result = $this->callProtected($validator, 'validateValue', $controlTotp->at(time() - 31)); - $this->assertEquals([E::TOTP_INCORRECT, []], $result); + $this->assertSame([E::TOTP_INCORRECT, []], $result); $validator->window = 2; $result = $this->callProtected($validator, 'validateValue', $controlTotp->at(time() - 31)); @@ -34,7 +34,7 @@ class TotpValidatorTest extends TestCase { $at = time() - 400; $validator->timestamp = $at; $result = $this->callProtected($validator, 'validateValue', $controlTotp->now()); - $this->assertEquals([E::TOTP_INCORRECT, []], $result); + $this->assertSame([E::TOTP_INCORRECT, []], $result); $result = $this->callProtected($validator, 'validateValue', $controlTotp->at($at)); $this->assertNull($result); diff --git a/api/web/index.php b/api/web/index.php index 306baf5..e6e45e4 100644 --- a/api/web/index.php +++ b/api/web/index.php @@ -8,8 +8,8 @@ $time = microtime(true); require __DIR__ . '/../../vendor/autoload.php'; -defined('YII_DEBUG') or define('YII_DEBUG', in_array(getenv('YII_DEBUG'), ['true', '1'])); -defined('YII_ENV') or define('YII_ENV', getenv('YII_ENV')); +defined('YII_DEBUG') || define('YII_DEBUG', in_array(getenv('YII_DEBUG'), ['true', '1'])); +defined('YII_ENV') || define('YII_ENV', getenv('YII_ENV')); // Initialize an application aspect container AspectKernel::getInstance()->init([ diff --git a/common/behaviors/PrimaryKeyValueBehavior.php b/common/behaviors/PrimaryKeyValueBehavior.php index 0882f20..20889a5 100644 --- a/common/behaviors/PrimaryKeyValueBehavior.php +++ b/common/behaviors/PrimaryKeyValueBehavior.php @@ -18,7 +18,7 @@ class PrimaryKeyValueBehavior extends Behavior { */ public $value; - public function events() { + public function events(): array { return [ ActiveRecord::EVENT_BEFORE_INSERT => 'setPrimaryKeyValue', ]; @@ -32,7 +32,7 @@ class PrimaryKeyValueBehavior extends Behavior { return true; } - public function refreshPrimaryKeyValue() { + public function refreshPrimaryKeyValue(): void { do { $key = $this->generateValue(); } while ($this->isValueExists($key)); @@ -45,15 +45,18 @@ class PrimaryKeyValueBehavior extends Behavior { } protected function isValueExists(string $key): bool { - return $this->owner->find()->andWhere([$this->getPrimaryKeyName() => $key])->exists(); + $owner = $this->owner; + return $owner::find()->andWhere([$this->getPrimaryKeyName() => $key])->exists(); } protected function getPrimaryKeyName(): string { $owner = $this->owner; - $primaryKeys = $owner->primaryKey(); + $primaryKeys = $owner::primaryKey(); if (!isset($primaryKeys[0])) { throw new InvalidConfigException('"' . get_class($owner) . '" must have a primary key.'); - } elseif (count($primaryKeys) > 1) { + } + + if (count($primaryKeys) > 1) { throw new InvalidConfigException('Current behavior don\'t support models with more then one primary key.'); } diff --git a/common/components/Mojang/Api.php b/common/components/Mojang/Api.php index cb92122..37a65a1 100644 --- a/common/components/Mojang/Api.php +++ b/common/components/Mojang/Api.php @@ -26,7 +26,9 @@ class Api { $response = $this->getClient()->get($this->buildUsernameToUUIDRoute($username), $query); if ($response->getStatusCode() === 204) { throw new NoContentException('Username not found'); - } elseif ($response->getStatusCode() !== 200) { + } + + if ($response->getStatusCode() !== 200) { throw new MojangApiException('Unexpected request result'); } diff --git a/common/models/UsernameHistory.php b/common/models/UsernameHistory.php index bba421b..8ffc061 100644 --- a/common/models/UsernameHistory.php +++ b/common/models/UsernameHistory.php @@ -45,7 +45,7 @@ class UsernameHistory extends ActiveRecord { * @param int $afterTime * @return UsernameHistory|null */ - public function findNext(int $afterTime = null): ?UsernameHistory { + public function findNext(int $afterTime = null): ?self { return self::find() ->andWhere(['account_id' => $this->account_id]) ->andWhere(['>', 'applied_in', $afterTime ?: $this->applied_in]) diff --git a/common/tests/_bootstrap.php b/common/tests/_bootstrap.php index 41318a6..ea96bfa 100644 --- a/common/tests/_bootstrap.php +++ b/common/tests/_bootstrap.php @@ -1,7 +1,7 @@ behaviors['dataBehavior']; $this->callProtected($behavior, 'setKey', 'my-key', 'my-value'); - $this->assertEquals(serialize(['my-key' => 'my-value']), $model->_data); + $this->assertSame(serialize(['my-key' => 'my-value']), $model->_data); } public function testGetKey() { @@ -25,7 +25,7 @@ class DataBehaviorTest extends TestCase { $model->_data = serialize(['some-key' => 'some-value']); /** @var DataBehavior $behavior */ $behavior = $model->behaviors['dataBehavior']; - $this->assertEquals('some-value', $this->callProtected($behavior, 'getKey', 'some-key')); + $this->assertSame('some-value', $this->callProtected($behavior, 'getKey', 'some-key')); } public function testGetData() { diff --git a/common/tests/unit/behaviors/EmailActivationExpirationBehaviorTest.php b/common/tests/unit/behaviors/EmailActivationExpirationBehaviorTest.php index 91ed3b1..b25d142 100644 --- a/common/tests/unit/behaviors/EmailActivationExpirationBehaviorTest.php +++ b/common/tests/unit/behaviors/EmailActivationExpirationBehaviorTest.php @@ -15,7 +15,7 @@ class EmailActivationExpirationBehaviorTest extends TestCase { $behavior = $this->createBehavior(); $time = time(); $behavior->owner->created_at = $time; - $this->assertEquals($time + 10, $this->callProtected($behavior, 'calculateTime', 10)); + $this->assertSame($time + 10, $this->callProtected($behavior, 'calculateTime', 10)); } public function testCompareTime() { diff --git a/common/tests/unit/components/Mojang/ApiTest.php b/common/tests/unit/components/Mojang/ApiTest.php index 62bf1db..b958833 100644 --- a/common/tests/unit/components/Mojang/ApiTest.php +++ b/common/tests/unit/components/Mojang/ApiTest.php @@ -31,8 +31,8 @@ class ApiTest extends TestCase { $this->handler->append(new Response(200, [], '{"id": "7125ba8b1c864508b92bb5c042ccfe2b","name": "KrisJelbring"}')); $response = (new Api())->usernameToUUID('KrisJelbring'); $this->assertInstanceOf(UsernameToUUIDResponse::class, $response); - $this->assertEquals('7125ba8b1c864508b92bb5c042ccfe2b', $response->id); - $this->assertEquals('KrisJelbring', $response->name); + $this->assertSame('7125ba8b1c864508b92bb5c042ccfe2b', $response->id); + $this->assertSame('KrisJelbring', $response->name); } /** diff --git a/common/tests/unit/db/mysql/QueryBuilderTest.php b/common/tests/unit/db/mysql/QueryBuilderTest.php index d6505ec..6a8a635 100644 --- a/common/tests/unit/db/mysql/QueryBuilderTest.php +++ b/common/tests/unit/db/mysql/QueryBuilderTest.php @@ -10,7 +10,7 @@ class QueryBuilderTest extends TestCase { public function testBuildOrderByField() { $queryBuilder = new QueryBuilder(Yii::$app->db); $result = $queryBuilder->buildOrderBy(['dummy' => ['first', 'second']]); - $this->assertEquals("ORDER BY FIELD(`dummy`,'first','second')", $result); + $this->assertSame("ORDER BY FIELD(`dummy`,'first','second')", $result); } } diff --git a/common/tests/unit/emails/TemplateTest.php b/common/tests/unit/emails/TemplateTest.php index e3bdeb1..b563fa4 100644 --- a/common/tests/unit/emails/TemplateTest.php +++ b/common/tests/unit/emails/TemplateTest.php @@ -14,7 +14,7 @@ class TemplateTest extends TestCase { public function testConstructor() { /** @var Template|\Mockery\MockInterface $template */ $template = mock(Template::class, ['find-me'])->makePartial(); - $this->assertEquals('find-me', $template->getTo()); + $this->assertSame('find-me', $template->getTo()); $this->assertInstanceOf(MailerInterface::class, $template->getMailer()); } @@ -22,13 +22,13 @@ class TemplateTest extends TestCase { Yii::$app->params['fromEmail'] = 'find-me'; /** @var Template|\Mockery\MockInterface $template */ $template = mock(Template::class)->makePartial(); - $this->assertEquals(['find-me' => 'Ely.by Accounts'], $template->getFrom()); + $this->assertSame(['find-me' => 'Ely.by Accounts'], $template->getFrom()); } public function testGetParams() { /** @var Template|\Mockery\MockInterface $template */ $template = mock(Template::class)->makePartial(); - $this->assertEquals([], $template->getParams()); + $this->assertSame([], $template->getParams()); } public function testCreateMessage() { @@ -39,9 +39,9 @@ class TemplateTest extends TestCase { /** @var MessageInterface $message */ $message = $this->callProtected($template, 'createMessage'); $this->assertInstanceOf(MessageInterface::class, $message); - $this->assertEquals(['to@ely.by' => 'To'], $message->getTo()); - $this->assertEquals(['from@ely.by' => 'Ely.by Accounts'], $message->getFrom()); - $this->assertEquals('mock-subject', $message->getSubject()); + $this->assertSame(['to@ely.by' => 'To'], $message->getTo()); + $this->assertSame(['from@ely.by' => 'Ely.by Accounts'], $message->getFrom()); + $this->assertSame('mock-subject', $message->getSubject()); } } diff --git a/common/tests/unit/emails/TemplateWithRendererTest.php b/common/tests/unit/emails/TemplateWithRendererTest.php index 0ed2971..08e2aa5 100644 --- a/common/tests/unit/emails/TemplateWithRendererTest.php +++ b/common/tests/unit/emails/TemplateWithRendererTest.php @@ -15,8 +15,8 @@ class TemplateWithRendererTest extends TestCase { public function testConstructor() { /** @var TemplateWithRenderer|\Mockery\MockInterface $template */ $template = mock(TemplateWithRenderer::class, ['mock-to', 'mock-locale'])->makePartial(); - $this->assertEquals('mock-to', $template->getTo()); - $this->assertEquals('mock-locale', $template->getLocale()); + $this->assertSame('mock-to', $template->getTo()); + $this->assertSame('mock-locale', $template->getLocale()); $this->assertInstanceOf(MailerInterface::class, $template->getMailer()); $this->assertInstanceOf(EmailRenderer::class, $template->getEmailRenderer()); } @@ -40,10 +40,10 @@ class TemplateWithRendererTest extends TestCase { /** @var \yii\swiftmailer\Message $message */ $message = $this->callProtected($template, 'createMessage'); $this->assertInstanceOf(MessageInterface::class, $message); - $this->assertEquals(['to@ely.by' => 'To'], $message->getTo()); - $this->assertEquals(['from@ely.by' => 'From'], $message->getFrom()); - $this->assertEquals('mock-subject', $message->getSubject()); - $this->assertEquals('mock-html', $message->getSwiftMessage()->getBody()); + $this->assertSame(['to@ely.by' => 'To'], $message->getTo()); + $this->assertSame(['from@ely.by' => 'From'], $message->getFrom()); + $this->assertSame('mock-subject', $message->getSubject()); + $this->assertSame('mock-html', $message->getSwiftMessage()->getBody()); } } diff --git a/common/tests/unit/helpers/StringHelperTest.php b/common/tests/unit/helpers/StringHelperTest.php index 56a2035..4d9a84f 100644 --- a/common/tests/unit/helpers/StringHelperTest.php +++ b/common/tests/unit/helpers/StringHelperTest.php @@ -7,11 +7,11 @@ use common\tests\unit\TestCase; class StringHelperTest extends TestCase { public function testGetEmailMask() { - $this->assertEquals('**@ely.by', StringHelper::getEmailMask('e@ely.by')); - $this->assertEquals('e**@ely.by', StringHelper::getEmailMask('es@ely.by')); - $this->assertEquals('e**i@ely.by', StringHelper::getEmailMask('eri@ely.by')); - $this->assertEquals('er**ch@ely.by', StringHelper::getEmailMask('erickskrauch@ely.by')); - $this->assertEquals('эр**уч@елу.бел', StringHelper::getEmailMask('эрикскрауч@елу.бел')); + $this->assertSame('**@ely.by', StringHelper::getEmailMask('e@ely.by')); + $this->assertSame('e**@ely.by', StringHelper::getEmailMask('es@ely.by')); + $this->assertSame('e**i@ely.by', StringHelper::getEmailMask('eri@ely.by')); + $this->assertSame('er**ch@ely.by', StringHelper::getEmailMask('erickskrauch@ely.by')); + $this->assertSame('эр**уч@елу.бел', StringHelper::getEmailMask('эрикскрауч@елу.бел')); } public function testIsUuid() { @@ -25,7 +25,7 @@ class StringHelperTest extends TestCase { */ public function testTrim($expected, $string) { $result = StringHelper::trim($string); - $this->assertEquals($expected, $result); + $this->assertSame($expected, $result); } /** diff --git a/common/tests/unit/models/AccountSessionTest.php b/common/tests/unit/models/AccountSessionTest.php index ca429f1..46b8a6c 100644 --- a/common/tests/unit/models/AccountSessionTest.php +++ b/common/tests/unit/models/AccountSessionTest.php @@ -15,13 +15,13 @@ class AccountSessionTest extends TestCase { public function testSetIp() { $model = new AccountSession(); $model->setIp('127.0.0.1'); - $this->assertEquals(2130706433, $model->last_used_ip, 'method should convert passed ip string to long'); + $this->assertSame(2130706433, $model->last_used_ip, 'method should convert passed ip string to long'); } public function testGetReadableIp() { $model = new AccountSession(); $model->last_used_ip = 2130706433; - $this->assertEquals('127.0.0.1', $model->getReadableIp(), 'method should convert stored long into readable ip'); + $this->assertSame('127.0.0.1', $model->getReadableIp(), 'method should convert stored long into readable ip'); } } diff --git a/common/tests/unit/models/AccountTest.php b/common/tests/unit/models/AccountTest.php index fe0b7ae..0f8a31e 100644 --- a/common/tests/unit/models/AccountTest.php +++ b/common/tests/unit/models/AccountTest.php @@ -23,7 +23,7 @@ class AccountTest extends TestCase { $model->setPassword('12345678'); $this->assertNotEmpty($model->password_hash, 'hash should be set'); $this->assertTrue($model->validatePassword('12345678'), 'validation should be passed'); - $this->assertEquals(Account::PASS_HASH_STRATEGY_YII2, $model->password_hash_strategy, 'latest password hash should be used'); + $this->assertSame(Account::PASS_HASH_STRATEGY_YII2, $model->password_hash_strategy, 'latest password hash should be used'); } public function testValidatePassword() { @@ -83,7 +83,7 @@ class AccountTest extends TestCase { public function testGetProfileLink() { $model = new Account(); $model->id = '123'; - $this->assertEquals('http://ely.by/u123', $model->getProfileLink()); + $this->assertSame('http://ely.by/u123', $model->getProfileLink()); } public function testIsAgreedWithActualRules() { @@ -108,9 +108,9 @@ class AccountTest extends TestCase { public function testSetRegistrationIp() { $account = new Account(); $account->setRegistrationIp('42.72.205.204'); - $this->assertEquals('42.72.205.204', inet_ntop($account->registration_ip)); + $this->assertSame('42.72.205.204', inet_ntop($account->registration_ip)); $account->setRegistrationIp('2001:1620:28:1:b6f:8bca:93:a116'); - $this->assertEquals('2001:1620:28:1:b6f:8bca:93:a116', inet_ntop($account->registration_ip)); + $this->assertSame('2001:1620:28:1:b6f:8bca:93:a116', inet_ntop($account->registration_ip)); $account->setRegistrationIp(null); $this->assertNull($account->registration_ip); } @@ -118,9 +118,9 @@ class AccountTest extends TestCase { public function testGetRegistrationIp() { $account = new Account(); $account->setRegistrationIp('42.72.205.204'); - $this->assertEquals('42.72.205.204', $account->getRegistrationIp()); + $this->assertSame('42.72.205.204', $account->getRegistrationIp()); $account->setRegistrationIp('2001:1620:28:1:b6f:8bca:93:a116'); - $this->assertEquals('2001:1620:28:1:b6f:8bca:93:a116', $account->getRegistrationIp()); + $this->assertSame('2001:1620:28:1:b6f:8bca:93:a116', $account->getRegistrationIp()); $account->setRegistrationIp(null); $this->assertNull($account->getRegistrationIp()); } diff --git a/common/tests/unit/tasks/ClearOauthSessionsTest.php b/common/tests/unit/tasks/ClearOauthSessionsTest.php index 25835bc..1f3ac8f 100644 --- a/common/tests/unit/tasks/ClearOauthSessionsTest.php +++ b/common/tests/unit/tasks/ClearOauthSessionsTest.php @@ -29,7 +29,7 @@ class ClearOauthSessionsTest extends TestCase { $result = ClearOauthSessions::createFromOauthClient($client, time()); $this->assertInstanceOf(ClearOauthSessions::class, $result); $this->assertSame('mocked-id', $result->clientId); - $this->assertEquals(time(), $result->notSince, '', 1); + $this->assertEqualsWithDelta(time(), $result->notSince, 1); } public function testExecute() { diff --git a/common/tests/unit/tasks/DeliveryWebHookTest.php b/common/tests/unit/tasks/DeliveryWebHookTest.php index 1a002f9..e2f980e 100644 --- a/common/tests/unit/tasks/DeliveryWebHookTest.php +++ b/common/tests/unit/tasks/DeliveryWebHookTest.php @@ -53,7 +53,7 @@ class DeliveryWebHookTest extends TestCase { $this->assertSame('account.edit', $request->getHeaders()['X-Ely-Accounts-Event'][0]); $this->assertSame('application/x-www-form-urlencoded', $request->getHeaders()['Content-Type'][0]); $this->assertArrayNotHasKey('X-Hub-Signature', $request->getHeaders()); - $this->assertEquals('key=value&another=value', (string)$request->getBody()); + $this->assertSame('key=value&another=value', (string)$request->getBody()); } public function testExecuteSuccessDeliveryWithSignature() { @@ -74,7 +74,7 @@ class DeliveryWebHookTest extends TestCase { $this->assertSame('account.edit', $request->getHeaders()['X-Ely-Accounts-Event'][0]); $this->assertSame('application/x-www-form-urlencoded', $request->getHeaders()['Content-Type'][0]); $this->assertSame('sha1=3c0b1eef564b2d3a5e9c0f2a8302b1b42b3d4784', $request->getHeaders()['X-Hub-Signature'][0]); - $this->assertEquals('key=value&another=value', (string)$request->getBody()); + $this->assertSame('key=value&another=value', (string)$request->getBody()); } public function testExecuteHandleClientException() { diff --git a/common/tests/unit/tasks/PullMojangUsernameTest.php b/common/tests/unit/tasks/PullMojangUsernameTest.php index 1fdfce3..df97827 100644 --- a/common/tests/unit/tasks/PullMojangUsernameTest.php +++ b/common/tests/unit/tasks/PullMojangUsernameTest.php @@ -142,7 +142,7 @@ class PullMojangUsernameTest extends TestCase { /** @var MojangUsername|null $mojangUsername */ $mojangUsername = MojangUsername::findOne($username); $this->assertInstanceOf(MojangUsername::class, $mojangUsername); - $this->assertNotEquals($mojangInfo->uuid, $mojangUsername->uuid); + $this->assertNotSame($mojangInfo->uuid, $mojangUsername->uuid); } } diff --git a/common/tests/unit/validators/EmailValidatorTest.php b/common/tests/unit/validators/EmailValidatorTest.php index b9f985e..711c2d8 100644 --- a/common/tests/unit/validators/EmailValidatorTest.php +++ b/common/tests/unit/validators/EmailValidatorTest.php @@ -26,18 +26,18 @@ class EmailValidatorTest extends TestCase { $model = $this->createModel("testemail@ely.by\u{feff}"); // Zero width no-break space (U+FEFF) $this->validator->validateAttribute($model, 'field'); - $this->assertEquals(['error.email_invalid'], $model->getErrors('field')); - $this->assertEquals('testemail@ely.by', $model->field); + $this->assertSame(['error.email_invalid'], $model->getErrors('field')); + $this->assertSame('testemail@ely.by', $model->field); } public function testValidateAttributeRequired() { $model = $this->createModel(''); $this->validator->validateAttribute($model, 'field'); - $this->assertEquals(['error.email_required'], $model->getErrors('field')); + $this->assertSame(['error.email_required'], $model->getErrors('field')); $model = $this->createModel('email'); $this->validator->validateAttribute($model, 'field'); - $this->assertNotEquals(['error.email_required'], $model->getErrors('field')); + $this->assertNotSame(['error.email_required'], $model->getErrors('field')); } public function testValidateAttributeLength() { @@ -49,11 +49,11 @@ class EmailValidatorTest extends TestCase { '@gmail.com' // = 256 symbols ); $this->validator->validateAttribute($model, 'field'); - $this->assertEquals(['error.email_too_long'], $model->getErrors('field')); + $this->assertSame(['error.email_too_long'], $model->getErrors('field')); $model = $this->createModel('some-email@gmail.com'); $this->validator->validateAttribute($model, 'field'); - $this->assertNotEquals(['error.email_too_long'], $model->getErrors('field')); + $this->assertNotSame(['error.email_too_long'], $model->getErrors('field')); } public function testValidateAttributeEmail() { @@ -61,15 +61,15 @@ class EmailValidatorTest extends TestCase { $model = $this->createModel('non-email'); $this->validator->validateAttribute($model, 'field'); - $this->assertEquals(['error.email_invalid'], $model->getErrors('field')); + $this->assertSame(['error.email_invalid'], $model->getErrors('field')); $model = $this->createModel('non-email@etot-domen-ne-suschestrvyet.de'); $this->validator->validateAttribute($model, 'field'); - $this->assertEquals(['error.email_invalid'], $model->getErrors('field')); + $this->assertSame(['error.email_invalid'], $model->getErrors('field')); $model = $this->createModel('valid-email@gmail.com'); $this->validator->validateAttribute($model, 'field'); - $this->assertNotEquals(['error.email_invalid'], $model->getErrors('field')); + $this->assertNotSame(['error.email_invalid'], $model->getErrors('field')); } public function testValidateAttributeTempmail() { @@ -77,11 +77,11 @@ class EmailValidatorTest extends TestCase { $model = $this->createModel('ibrpycwyjdnt@dropmail.me'); $this->validator->validateAttribute($model, 'field'); - $this->assertEquals(['error.email_is_tempmail'], $model->getErrors('field')); + $this->assertSame(['error.email_is_tempmail'], $model->getErrors('field')); $model = $this->createModel('valid-email@gmail.com'); $this->validator->validateAttribute($model, 'field'); - $this->assertNotEquals(['error.email_is_tempmail'], $model->getErrors('field')); + $this->assertNotSame(['error.email_is_tempmail'], $model->getErrors('field')); } public function testValidateAttributeIdna() { @@ -108,19 +108,19 @@ class EmailValidatorTest extends TestCase { $model = $this->createModel($accountFixture->email); $this->validator->validateAttribute($model, 'field'); - $this->assertEquals(['error.email_not_available'], $model->getErrors('field')); + $this->assertSame(['error.email_not_available'], $model->getErrors('field')); $model = $this->createModel($accountFixture->email); $this->validator->accountCallback = function() use ($accountFixture) { return $accountFixture->id; }; $this->validator->validateAttribute($model, 'field'); - $this->assertNotEquals(['error.email_not_available'], $model->getErrors('field')); + $this->assertNotSame(['error.email_not_available'], $model->getErrors('field')); $this->validator->accountCallback = null; $model = $this->createModel('some-unique-email@gmail.com'); $this->validator->validateAttribute($model, 'field'); - $this->assertNotEquals(['error.email_not_available'], $model->getErrors('field')); + $this->assertNotSame(['error.email_not_available'], $model->getErrors('field')); } /** diff --git a/common/tests/unit/validators/MinecraftServerAddressValidatorTest.php b/common/tests/unit/validators/MinecraftServerAddressValidatorTest.php index 914dd3b..a0acdc7 100644 --- a/common/tests/unit/validators/MinecraftServerAddressValidatorTest.php +++ b/common/tests/unit/validators/MinecraftServerAddressValidatorTest.php @@ -11,18 +11,23 @@ class MinecraftServerAddressValidatorTest extends TestCase { */ public function testValidate($address, $shouldBeValid) { $validator = new MinecraftServerAddressValidator(); + $validator->message = 'mock message'; $validator->validate($address, $errors); - $this->assertEquals($shouldBeValid, $errors === null); + if ($shouldBeValid) { + $this->assertNull($errors); + } else { + $this->assertSame('mock message', $errors); + } } public function domainNames() { return [ - ['localhost', true ], - ['localhost:25565', true ], - ['mc.hypixel.net', true ], - ['mc.hypixel.net:25565', true ], - ['136.243.88.97', true ], - ['136.243.88.97:25565', true ], + ['localhost', true], + ['localhost:25565', true], + ['mc.hypixel.net', true], + ['mc.hypixel.net:25565', true], + ['136.243.88.97', true], + ['136.243.88.97:25565', true], ['http://ely.by', false], ['http://ely.by:80', false], ['ely.by/abcd', false], diff --git a/common/tests/unit/validators/UsernameValidatorTest.php b/common/tests/unit/validators/UsernameValidatorTest.php index 7328943..0a32634 100644 --- a/common/tests/unit/validators/UsernameValidatorTest.php +++ b/common/tests/unit/validators/UsernameValidatorTest.php @@ -21,33 +21,33 @@ class UsernameValidatorTest extends TestCase { public function testValidateTrimming() { $model = $this->createModel("HereIsJohnny#\u{feff}"); // Zero width no-break space (U+FEFF) $this->validator->validateAttribute($model, 'field'); - $this->assertEquals(['error.username_invalid'], $model->getErrors('field')); - $this->assertEquals('HereIsJohnny#', $model->field); + $this->assertSame(['error.username_invalid'], $model->getErrors('field')); + $this->assertSame('HereIsJohnny#', $model->field); } public function testValidateAttributeRequired() { $model = $this->createModel(''); $this->validator->validateAttribute($model, 'field'); - $this->assertEquals(['error.username_required'], $model->getErrors('field')); + $this->assertSame(['error.username_required'], $model->getErrors('field')); $model = $this->createModel('username'); $this->validator->validateAttribute($model, 'field'); - $this->assertNotEquals(['error.username_required'], $model->getErrors('field')); + $this->assertNotSame(['error.username_required'], $model->getErrors('field')); } public function testValidateAttributeLength() { $model = $this->createModel('at'); $this->validator->validateAttribute($model, 'field'); - $this->assertEquals(['error.username_too_short'], $model->getErrors('field')); + $this->assertSame(['error.username_too_short'], $model->getErrors('field')); $model = $this->createModel('erickskrauch_erickskrauch'); $this->validator->validateAttribute($model, 'field'); - $this->assertEquals(['error.username_too_long'], $model->getErrors('field')); + $this->assertSame(['error.username_too_long'], $model->getErrors('field')); $model = $this->createModel('username'); $this->validator->validateAttribute($model, 'field'); - $this->assertNotEquals(['error.username_too_short'], $model->getErrors('field')); - $this->assertNotEquals(['error.username_too_long'], $model->getErrors('field')); + $this->assertNotSame(['error.username_too_short'], $model->getErrors('field')); + $this->assertNotSame(['error.username_too_long'], $model->getErrors('field')); } // TODO: rewrite this test with @provider usage @@ -59,7 +59,7 @@ class UsernameValidatorTest extends TestCase { foreach ($shouldBeValid as $nickname) { $model = $this->createModel($nickname); $this->validator->validateAttribute($model, 'field'); - $this->assertNotEquals(['error.username_invalid'], $model->getErrors('field')); + $this->assertNotSame(['error.username_invalid'], $model->getErrors('field')); } $shouldBeInvalid = [ @@ -68,7 +68,7 @@ class UsernameValidatorTest extends TestCase { foreach ($shouldBeInvalid as $nickname) { $model = $this->createModel($nickname); $this->validator->validateAttribute($model, 'field'); - $this->assertEquals(['error.username_invalid'], $model->getErrors('field')); + $this->assertSame(['error.username_invalid'], $model->getErrors('field')); } } @@ -82,19 +82,19 @@ class UsernameValidatorTest extends TestCase { $model = $this->createModel($accountFixture->username); $this->validator->validateAttribute($model, 'field'); - $this->assertEquals(['error.username_not_available'], $model->getErrors('field')); + $this->assertSame(['error.username_not_available'], $model->getErrors('field')); $model = $this->createModel($accountFixture->username); $this->validator->accountCallback = function() use ($accountFixture) { return $accountFixture->id; }; $this->validator->validateAttribute($model, 'field'); - $this->assertNotEquals(['error.username_not_available'], $model->getErrors('field')); + $this->assertNotSame(['error.username_not_available'], $model->getErrors('field')); $this->validator->accountCallback = null; $model = $this->createModel('some-unique-username'); $this->validator->validateAttribute($model, 'field'); - $this->assertNotEquals(['error.username_not_available'], $model->getErrors('field')); + $this->assertNotSame(['error.username_not_available'], $model->getErrors('field')); } /** diff --git a/common/tests/unit/validators/UuidValidatorTest.php b/common/tests/unit/validators/UuidValidatorTest.php index d45cc19..191af72 100644 --- a/common/tests/unit/validators/UuidValidatorTest.php +++ b/common/tests/unit/validators/UuidValidatorTest.php @@ -16,7 +16,7 @@ class UuidValidatorTest extends TestCase { $model = $this->createModel(); $validator->validateAttribute($model, 'attribute'); $this->assertTrue($model->hasErrors()); - $this->assertEquals(['Attribute must be valid uuid'], $model->getErrors('attribute')); + $this->assertSame(['Attribute must be valid uuid'], $model->getErrors('attribute')); }); $this->specify('expected error if passed invalid string', function() { @@ -25,7 +25,7 @@ class UuidValidatorTest extends TestCase { $model->attribute = '123456789'; $validator->validateAttribute($model, 'attribute'); $this->assertTrue($model->hasErrors()); - $this->assertEquals(['Attribute must be valid uuid'], $model->getErrors('attribute')); + $this->assertSame(['Attribute must be valid uuid'], $model->getErrors('attribute')); }); $this->specify('no errors if passed nil uuid and allowNil is set to true', function() { @@ -43,7 +43,7 @@ class UuidValidatorTest extends TestCase { $model->attribute = '00000000-0000-0000-0000-000000000000'; $validator->validateAttribute($model, 'attribute'); $this->assertTrue($model->hasErrors()); - $this->assertEquals(['Attribute must be valid uuid'], $model->getErrors('attribute')); + $this->assertSame(['Attribute must be valid uuid'], $model->getErrors('attribute')); }); $this->specify('no errors if passed valid uuid', function() { @@ -61,7 +61,7 @@ class UuidValidatorTest extends TestCase { $model->attribute = str_replace('-', '', $originalUuid); $validator->validateAttribute($model, 'attribute'); $this->assertFalse($model->hasErrors()); - $this->assertEquals($originalUuid, $model->attribute); + $this->assertSame($originalUuid, $model->attribute); }); } diff --git a/composer.json b/composer.json index 9f4e12a..c69b94e 100644 --- a/composer.json +++ b/composer.json @@ -7,6 +7,7 @@ "require": { "php": "^7.2", "ext-json": "*", + "ext-mbstring": "*", "ext-pdo": "*", "ext-libxml": "*", "ext-simplexml": "*", @@ -37,7 +38,7 @@ "codeception/verify": "*", "mockery/mockery": "^1.0.0", "php-mock/php-mock-mockery": "^1.2.0", - "ely/php-code-style": "^0.1.0", + "ely/php-code-style": "^0.3.0", "predis/predis": "^1.1", "roave/security-advisories": "dev-master" }, diff --git a/composer.lock b/composer.lock index c989311..b6118c3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c0a5d0472eaecefbba5199888a4232ae", + "content-hash": "edb3d935ad36f30c49f8a4db6132747a", "packages": [ { "name": "bacon/bacon-qr-code", @@ -118,8 +118,7 @@ "dist": { "type": "zip", "url": "https://api.github.com/repos/RobinHerbots/Inputmask/zipball/5e670ad62f50c738388d4dcec78d2888505ad77b", - "reference": "5e670ad62f50c738388d4dcec78d2888505ad77b", - "shasum": null + "reference": "5e670ad62f50c738388d4dcec78d2888505ad77b" }, "require": { "bower-asset/jquery": ">=1.7" @@ -140,8 +139,7 @@ "dist": { "type": "zip", "url": "https://api.github.com/repos/jquery/jquery-dist/zipball/77d2a51d0520d2ee44173afdf4e40a9201f5964e", - "reference": "77d2a51d0520d2ee44173afdf4e40a9201f5964e", - "shasum": null + "reference": "77d2a51d0520d2ee44173afdf4e40a9201f5964e" }, "type": "bower-asset", "license": [ @@ -159,8 +157,7 @@ "dist": { "type": "zip", "url": "https://api.github.com/repos/bestiejs/punycode.js/zipball/38c8d3131a82567bfef18da09f7f4db68c84f8a3", - "reference": "38c8d3131a82567bfef18da09f7f4db68c84f8a3", - "shasum": null + "reference": "38c8d3131a82567bfef18da09f7f4db68c84f8a3" }, "type": "bower-asset" }, @@ -175,8 +172,7 @@ "dist": { "type": "zip", "url": "https://api.github.com/repos/getsentry/raven-js-bower/zipball/c8b3a6040be6928e2f57fa5eec4d7afc31750235", - "reference": "c8b3a6040be6928e2f57fa5eec4d7afc31750235", - "shasum": null + "reference": "c8b3a6040be6928e2f57fa5eec4d7afc31750235" }, "type": "bower-asset" }, @@ -191,8 +187,7 @@ "dist": { "type": "zip", "url": "https://api.github.com/repos/yiisoft/jquery-pjax/zipball/aef7b953107264f00234902a3880eb50dafc48be", - "reference": "aef7b953107264f00234902a3880eb50dafc48be", - "shasum": null + "reference": "aef7b953107264f00234902a3880eb50dafc48be" }, "require": { "bower-asset/jquery": ">=1.8" @@ -2398,8 +2393,7 @@ "dist": { "type": "zip", "url": "https://api.github.com/repos/twbs/bootstrap/zipball/68b0d231a13201eb14acd3dc84e51543d16e5f7e", - "reference": "68b0d231a13201eb14acd3dc84e51543d16e5f7e", - "shasum": null + "reference": "68b0d231a13201eb14acd3dc84e51543d16e5f7e" }, "require": { "bower-asset/jquery": ">=1.9.1,<4.0" @@ -2814,24 +2808,24 @@ }, { "name": "ely/php-code-style", - "version": "0.1.0", + "version": "0.3.0", "source": { "type": "git", "url": "https://github.com/elyby/php-code-style.git", - "reference": "0bb3e8082753981af4775f5b95d159c9cd9c6bf4" + "reference": "2140798d0aca85f4fa3e70c77bfef066ce115d1a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/elyby/php-code-style/zipball/0bb3e8082753981af4775f5b95d159c9cd9c6bf4", - "reference": "0bb3e8082753981af4775f5b95d159c9cd9c6bf4", + "url": "https://api.github.com/repos/elyby/php-code-style/zipball/2140798d0aca85f4fa3e70c77bfef066ce115d1a", + "reference": "2140798d0aca85f4fa3e70c77bfef066ce115d1a", "shasum": "" }, "require": { - "friendsofphp/php-cs-fixer": "^2.11", + "friendsofphp/php-cs-fixer": "^2.13.0", "php": "^7.0" }, "require-dev": { - "phpunit/phpunit": "^7.0" + "phpunit/phpunit": "^6.5.1" }, "type": "library", "autoload": { @@ -2859,7 +2853,7 @@ "Code style", "php-cs-fixer" ], - "time": "2018-04-17T18:28:51+00:00" + "time": "2019-02-23T17:29:08+00:00" }, { "name": "facebook/webdriver", @@ -2964,27 +2958,27 @@ }, { "name": "friendsofphp/php-cs-fixer", - "version": "v2.12.2", + "version": "v2.14.2", "source": { "type": "git", "url": "https://github.com/FriendsOfPHP/PHP-CS-Fixer.git", - "reference": "dcc87d5414e9d0bd316fce81a5bedb9ce720b183" + "reference": "ff401e58261ffc5934a58f795b3f95b355e276cb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/dcc87d5414e9d0bd316fce81a5bedb9ce720b183", - "reference": "dcc87d5414e9d0bd316fce81a5bedb9ce720b183", + "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/ff401e58261ffc5934a58f795b3f95b355e276cb", + "reference": "ff401e58261ffc5934a58f795b3f95b355e276cb", "shasum": "" }, "require": { "composer/semver": "^1.4", - "composer/xdebug-handler": "^1.0", + "composer/xdebug-handler": "^1.2", "doctrine/annotations": "^1.2", "ext-json": "*", "ext-tokenizer": "*", - "php": "^5.6 || >=7.0 <7.3", + "php": "^5.6 || ^7.0", "php-cs-fixer/diff": "^1.3", - "symfony/console": "^3.2 || ^4.0", + "symfony/console": "^3.4.17 || ^4.1.6", "symfony/event-dispatcher": "^3.0 || ^4.0", "symfony/filesystem": "^3.0 || ^4.0", "symfony/finder": "^3.0 || ^4.0", @@ -2994,13 +2988,10 @@ "symfony/process": "^3.0 || ^4.0", "symfony/stopwatch": "^3.0 || ^4.0" }, - "conflict": { - "hhvm": "*" - }, "require-dev": { "johnkary/phpunit-speedtrap": "^1.1 || ^2.0 || ^3.0", "justinrainbow/json-schema": "^5.0", - "keradus/cli-executor": "^1.1", + "keradus/cli-executor": "^1.2", "mikey179/vfsstream": "^1.6", "php-coveralls/php-coveralls": "^2.1", "php-cs-fixer/accessible-object": "^1.0", @@ -3051,7 +3042,7 @@ } ], "description": "A tool to automatically fix PHP code style", - "time": "2018-07-06T10:37:40+00:00" + "time": "2019-02-17T17:44:13+00:00" }, { "name": "fzaninotto/faker", @@ -5876,6 +5867,7 @@ "platform": { "php": "^7.2", "ext-json": "*", + "ext-mbstring": "*", "ext-pdo": "*", "ext-libxml": "*", "ext-simplexml": "*" diff --git a/console/migrations/m171222_200114_migrate_to_utf8md4_unicode_ci.php b/console/migrations/m171222_200114_migrate_to_utf8md4_unicode_ci.php index 0fef2b7..3d007be 100644 --- a/console/migrations/m171222_200114_migrate_to_utf8md4_unicode_ci.php +++ b/console/migrations/m171222_200114_migrate_to_utf8md4_unicode_ci.php @@ -8,10 +8,10 @@ class m171222_200114_migrate_to_utf8md4_unicode_ci extends Migration { $this->execute('SET FOREIGN_KEY_CHECKS=0'); $dbName = $this->db->createCommand('SELECT DATABASE()')->queryScalar(); - $this->execute("ALTER DATABASE {{%$dbName}} CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci"); + $this->execute("ALTER DATABASE {{%{$dbName}}} CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci"); $tables = $this->db->createCommand('SHOW TABLES')->queryColumn(); foreach ($tables as $table) { - $this->execute("ALTER TABLE {{%$table}} CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"); + $this->execute("ALTER TABLE {{%{$table}}} CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"); } $this->execute('ALTER TABLE {{%usernames_history}} MODIFY username VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL'); @@ -23,10 +23,10 @@ class m171222_200114_migrate_to_utf8md4_unicode_ci extends Migration { $this->execute('SET FOREIGN_KEY_CHECKS=0'); $dbName = $this->db->createCommand('SELECT DATABASE()')->queryScalar(); - $this->execute("ALTER DATABASE {{%$dbName}} CHARACTER SET = utf8 COLLATE = utf8_general_ci"); + $this->execute("ALTER DATABASE {{%{$dbName}}} CHARACTER SET = utf8 COLLATE = utf8_general_ci"); $tables = $this->db->createCommand('SHOW TABLES')->queryColumn(); foreach ($tables as $table) { - $this->execute("ALTER TABLE {{%$table}} CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci"); + $this->execute("ALTER TABLE {{%{$table}}} CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci"); } $this->execute('ALTER TABLE {{%usernames_history}} MODIFY username VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL'); diff --git a/console/tests/_bootstrap.php b/console/tests/_bootstrap.php index 156889d..e919416 100644 --- a/console/tests/_bootstrap.php +++ b/console/tests/_bootstrap.php @@ -1,8 +1,8 @@ tester->grabFixture('emailActivations', 'deeplyExpiredConfirmation'); $controller = new CleanupController('cleanup', Yii::$app); - $this->assertEquals(0, $controller->actionEmailKeys()); + $this->assertSame(0, $controller->actionEmailKeys()); $this->tester->cantSeeRecord(EmailActivation::class, ['key' => $expiredConfirmation->key]); } @@ -40,7 +40,7 @@ class CleanupControllerTest extends TestCase { $expiredSession = $this->tester->grabFixture('minecraftSessions', 'expired-token'); $controller = new CleanupController('cleanup', Yii::$app); - $this->assertEquals(0, $controller->actionMinecraftSessions()); + $this->assertSame(0, $controller->actionMinecraftSessions()); $this->tester->cantSeeRecord(MinecraftAccessKey::class, ['access_token' => $expiredSession->access_token]); } @@ -53,11 +53,11 @@ class CleanupControllerTest extends TestCase { $totalSessionsCount = AccountSession::find()->count(); $controller = new CleanupController('cleanup', Yii::$app); - $this->assertEquals(0, $controller->actionWebSessions()); + $this->assertSame(0, $controller->actionWebSessions()); $this->tester->cantSeeRecord(AccountSession::class, ['id' => $expiredSession->id]); $this->tester->cantSeeRecord(AccountSession::class, ['id' => $notRefreshedSession->id]); - $this->assertEquals($totalSessionsCount - 2, AccountSession::find()->count()); + $this->assertSame($totalSessionsCount - 2, (int)AccountSession::find()->count()); } public function testActionOauthClients() { @@ -65,11 +65,11 @@ class CleanupControllerTest extends TestCase { $totalClientsCount = OauthClient::find()->includeDeleted()->count(); $controller = new CleanupController('cleanup', Yii::$app); - $this->assertEquals(0, $controller->actionOauthClients()); + $this->assertSame(0, $controller->actionOauthClients()); $this->assertNull(OauthClient::find()->includeDeleted()->andWhere(['id' => 'deleted-oauth-client'])->one()); $this->assertNotNull(OauthClient::find()->includeDeleted()->andWhere(['id' => 'deleted-oauth-client-with-sessions'])->one()); - $this->assertEquals($totalClientsCount - 1, OauthClient::find()->includeDeleted()->count()); + $this->assertSame($totalClientsCount - 1, (int)OauthClient::find()->includeDeleted()->count()); /** @var ClearOauthSessions $job */ $job = $this->tester->grabLastQueuedJob(); diff --git a/yii b/yii index 20610d6..0a9e27c 100755 --- a/yii +++ b/yii @@ -2,8 +2,8 @@