mirror of
https://github.com/elyby/accounts.git
synced 2024-11-22 21:23:19 +05:30
Update ely/php-code-style and run updated CS fixer
This commit is contained in:
parent
ea4ebd19ef
commit
b20825a051
@ -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()
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
* Этот метод используется для получения токена, к которому привязаны права.
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -42,9 +42,7 @@ class RefreshTokenForm extends ApiForm {
|
||||
$accessToken->refreshPrimaryKeyValue();
|
||||
$accessToken->update();
|
||||
|
||||
$dataModel = new AuthenticateData($accessToken);
|
||||
|
||||
return $dataModel;
|
||||
return new AuthenticateData($accessToken);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
defined('YII_DEBUG') or define('YII_DEBUG', true);
|
||||
defined('YII_ENV') or define('YII_ENV', 'test');
|
||||
defined('YII_DEBUG') || define('YII_DEBUG', true);
|
||||
defined('YII_ENV') || define('YII_ENV', 'test');
|
||||
|
||||
defined('YII_APP_BASE_PATH') or define('YII_APP_BASE_PATH', __DIR__ . '/../../');
|
||||
defined('YII_APP_BASE_PATH') || define('YII_APP_BASE_PATH', __DIR__ . '/../../');
|
||||
|
||||
require_once YII_APP_BASE_PATH . '/vendor/autoload.php';
|
||||
require_once YII_APP_BASE_PATH . '/vendor/yiisoft/yii2/Yii.php';
|
||||
|
@ -28,15 +28,15 @@ class OauthRoute extends BasePage {
|
||||
}
|
||||
|
||||
public function resetClient(string $clientId, bool $regenerateSecret = false): void {
|
||||
$this->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");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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() {
|
||||
|
@ -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());
|
||||
|
@ -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']);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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) {
|
||||
|
@ -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'],
|
||||
|
@ -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'
|
||||
|
@ -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() {
|
||||
|
@ -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',
|
||||
|
@ -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) {
|
||||
|
@ -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');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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]),
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -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']);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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', ''));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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'));
|
||||
|
@ -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);
|
||||
|
@ -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([
|
||||
|
@ -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.');
|
||||
}
|
||||
|
||||
|
@ -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');
|
||||
}
|
||||
|
||||
|
@ -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])
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
defined('YII_DEBUG') or define('YII_DEBUG', true);
|
||||
defined('YII_ENV') or define('YII_ENV', 'test');
|
||||
defined('YII_APP_BASE_PATH') or define('YII_APP_BASE_PATH', __DIR__ . '/../../');
|
||||
defined('YII_DEBUG') || define('YII_DEBUG', true);
|
||||
defined('YII_ENV') || define('YII_ENV', 'test');
|
||||
defined('YII_APP_BASE_PATH') || define('YII_APP_BASE_PATH', __DIR__ . '/../../');
|
||||
|
||||
require_once __DIR__ . '/../../vendor/autoload.php';
|
||||
require_once __DIR__ . '/../../vendor/yiisoft/yii2/Yii.php';
|
||||
|
@ -17,7 +17,7 @@ class DataBehaviorTest extends TestCase {
|
||||
/** @var DataBehavior $behavior */
|
||||
$behavior = $model->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() {
|
||||
|
@ -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() {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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() {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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],
|
||||
|
@ -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'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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"
|
||||
},
|
||||
|
56
composer.lock
generated
56
composer.lock
generated
@ -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": "*"
|
||||
|
@ -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');
|
||||
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
defined('YII_DEBUG') or define('YII_DEBUG', true);
|
||||
defined('YII_ENV') or define('YII_ENV', 'test');
|
||||
defined('YII_DEBUG') || define('YII_DEBUG', true);
|
||||
defined('YII_ENV') || define('YII_ENV', 'test');
|
||||
|
||||
defined('YII_APP_BASE_PATH') or define('YII_APP_BASE_PATH', __DIR__ . '/../../');
|
||||
defined('YII_APP_BASE_PATH') || define('YII_APP_BASE_PATH', __DIR__ . '/../../');
|
||||
|
||||
require_once YII_APP_BASE_PATH . '/vendor/autoload.php';
|
||||
require_once YII_APP_BASE_PATH . '/vendor/yiisoft/yii2/Yii.php';
|
||||
|
@ -30,7 +30,7 @@ class CleanupControllerTest extends TestCase {
|
||||
$expiredConfirmation = $this->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();
|
||||
|
4
yii
4
yii
@ -2,8 +2,8 @@
|
||||
<?php
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
defined('YII_DEBUG') or define('YII_DEBUG', (boolean)getenv('YII_DEBUG'));
|
||||
defined('YII_ENV') or define('YII_ENV', getenv('YII_ENV'));
|
||||
defined('YII_DEBUG') || define('YII_DEBUG', (bool)getenv('YII_DEBUG'));
|
||||
defined('YII_ENV') || define('YII_ENV', getenv('YII_ENV'));
|
||||
|
||||
require __DIR__ . '/vendor/yiisoft/yii2/Yii.php';
|
||||
require __DIR__ . '/common/config/bootstrap.php';
|
||||
|
Loading…
Reference in New Issue
Block a user