mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Upgrade project to PHP 8.3, add PHPStan, upgrade almost every dependency (#36)
* start updating to PHP 8.3 * taking off! Co-authored-by: ErickSkrauch <erickskrauch@yandex.ru> Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * dropped this Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * migrate to symfonymailer Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * this is so stupid 😭 Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * ah, free, at last. Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * oh, Gabriel. Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * now dawns thy reckoning. Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * and thy gore shall GLISTEN before the temples of man. Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * creature of steel. Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * my gratitude upon thee for my freedom. Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * but the crimes thy kind has committed against humanity Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * Upgrade PHP-CS-Fixer and do fix the codebase * First review round (maybe I have broken something) * are NOT forgotten. Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> * Enable parallel PHP-CS-Fixer runner * PHPStan level 1 * PHPStan level 2 * PHPStan level 3 * PHPStan level 4 * PHPStan level 5 * Levels 6 and 7 takes too much effort. Generate a baseline and fix them eventually * Resolve TODO's related to the php-mock * Drastically reduce baseline size with the Rector * More code modernization with help of the Rector * Update GitLab CI --------- Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com> Co-authored-by: ErickSkrauch <erickskrauch@yandex.ru>
This commit is contained in:
@@ -6,19 +6,19 @@ use common\tests\unit\TestCase;
|
||||
|
||||
class AccountSessionTest extends TestCase {
|
||||
|
||||
public function testGenerateRefreshToken() {
|
||||
public function testGenerateRefreshToken(): void {
|
||||
$model = new AccountSession();
|
||||
$model->generateRefreshToken();
|
||||
$this->assertNotNull($model->refresh_token, 'method call will set refresh_token value');
|
||||
}
|
||||
|
||||
public function testSetIp() {
|
||||
public function testSetIp(): void {
|
||||
$model = new AccountSession();
|
||||
$model->setIp('127.0.0.1');
|
||||
$this->assertSame(2130706433, $model->last_used_ip, 'method should convert passed ip string to long');
|
||||
}
|
||||
|
||||
public function testGetReadableIp() {
|
||||
public function testGetReadableIp(): void {
|
||||
$model = new AccountSession();
|
||||
$model->last_used_ip = 2130706433;
|
||||
$this->assertSame('127.0.0.1', $model->getReadableIp(), 'method should convert stored long into readable ip');
|
||||
|
||||
@@ -17,7 +17,7 @@ use const common\LATEST_RULES_VERSION;
|
||||
*/
|
||||
class AccountTest extends TestCase {
|
||||
|
||||
public function testSetPassword() {
|
||||
public function testSetPassword(): void {
|
||||
$model = new Account();
|
||||
$model->setPassword('12345678');
|
||||
$this->assertNotEmpty($model->password_hash, 'hash should be set');
|
||||
@@ -25,19 +25,17 @@ class AccountTest extends TestCase {
|
||||
$this->assertSame(Account::PASS_HASH_STRATEGY_YII2, $model->password_hash_strategy, 'latest password hash should be used');
|
||||
}
|
||||
|
||||
public function testValidatePassword() {
|
||||
public function testValidatePassword(): void {
|
||||
// Use old hashing algorithm
|
||||
$model = new Account();
|
||||
$model->email = 'erick@skrauch.net';
|
||||
$model->password_hash = '2cfdb29eb354af970865a923335d17d9'; // 12345678
|
||||
$model->password_hash_strategy = null; // To be sure it's not set
|
||||
$this->assertTrue($model->validatePassword('12345678', Account::PASS_HASH_STRATEGY_OLD_ELY), 'valid password should pass');
|
||||
$this->assertFalse($model->validatePassword('87654321', Account::PASS_HASH_STRATEGY_OLD_ELY), 'invalid password should fail');
|
||||
|
||||
// Modern hash algorithm should also work
|
||||
$model = new Account();
|
||||
$model->password_hash = '$2y$04$N0q8DaHzlYILCnLYrpZfEeWKEqkPZzbawiS07GbSr/.xbRNweSLU6'; // 12345678
|
||||
$model->password_hash_strategy = null; // To be sure it's not set
|
||||
$this->assertTrue($model->validatePassword('12345678', Account::PASS_HASH_STRATEGY_YII2), 'valid password should pass');
|
||||
$this->assertFalse($model->validatePassword('87654321', Account::PASS_HASH_STRATEGY_YII2), 'invalid password should fail');
|
||||
|
||||
@@ -57,7 +55,7 @@ class AccountTest extends TestCase {
|
||||
$this->assertFalse($model->validatePassword('87654321'), 'invalid password should fail');
|
||||
}
|
||||
|
||||
public function testHasMojangUsernameCollision() {
|
||||
public function testHasMojangUsernameCollision(): void {
|
||||
$model = new Account();
|
||||
$model->username = 'ErickSkrauch';
|
||||
$this->assertFalse($model->hasMojangUsernameCollision());
|
||||
@@ -69,13 +67,13 @@ class AccountTest extends TestCase {
|
||||
$this->assertTrue($model->hasMojangUsernameCollision());
|
||||
}
|
||||
|
||||
public function testGetProfileLink() {
|
||||
public function testGetProfileLink(): void {
|
||||
$model = new Account();
|
||||
$model->id = '123';
|
||||
$model->id = 123;
|
||||
$this->assertSame('http://ely.by/u123', $model->getProfileLink());
|
||||
}
|
||||
|
||||
public function testIsAgreedWithActualRules() {
|
||||
public function testIsAgreedWithActualRules(): void {
|
||||
$model = new Account();
|
||||
$this->assertFalse($model->isAgreedWithActualRules(), 'field is null');
|
||||
|
||||
@@ -86,7 +84,7 @@ class AccountTest extends TestCase {
|
||||
$this->assertTrue($model->isAgreedWithActualRules());
|
||||
}
|
||||
|
||||
public function testSetRegistrationIp() {
|
||||
public function testSetRegistrationIp(): void {
|
||||
$account = new Account();
|
||||
$account->setRegistrationIp('42.72.205.204');
|
||||
$this->assertSame('42.72.205.204', inet_ntop($account->registration_ip));
|
||||
@@ -96,7 +94,7 @@ class AccountTest extends TestCase {
|
||||
$this->assertNull($account->registration_ip);
|
||||
}
|
||||
|
||||
public function testGetRegistrationIp() {
|
||||
public function testGetRegistrationIp(): void {
|
||||
$account = new Account();
|
||||
$account->setRegistrationIp('42.72.205.204');
|
||||
$this->assertSame('42.72.205.204', $account->getRegistrationIp());
|
||||
@@ -106,7 +104,7 @@ class AccountTest extends TestCase {
|
||||
$this->assertNull($account->getRegistrationIp());
|
||||
}
|
||||
|
||||
public function testAfterSaveInsertEvent() {
|
||||
public function testAfterSaveInsertEvent(): void {
|
||||
$account = new Account();
|
||||
$account->afterSave(true, [
|
||||
'username' => 'old-username',
|
||||
@@ -114,7 +112,7 @@ class AccountTest extends TestCase {
|
||||
$this->assertNull($this->tester->grabLastQueuedJob());
|
||||
}
|
||||
|
||||
public function testAfterSaveNotMeaningfulAttributes() {
|
||||
public function testAfterSaveNotMeaningfulAttributes(): void {
|
||||
$account = new Account();
|
||||
$account->afterSave(false, [
|
||||
'updatedAt' => time(),
|
||||
@@ -122,7 +120,7 @@ class AccountTest extends TestCase {
|
||||
$this->assertNull($this->tester->grabLastQueuedJob());
|
||||
}
|
||||
|
||||
public function testAfterSavePushEvent() {
|
||||
public function testAfterSavePushEvent(): void {
|
||||
$changedAttributes = [
|
||||
'username' => 'old-username',
|
||||
'email' => 'old-email@ely.by',
|
||||
@@ -144,7 +142,7 @@ class AccountTest extends TestCase {
|
||||
$this->assertSame($changedAttributes, $notification->getPayloads()['changedAttributes']);
|
||||
}
|
||||
|
||||
public function testAfterDeletePushEvent() {
|
||||
public function testAfterDeletePushEvent(): void {
|
||||
$account = new Account();
|
||||
$account->id = 1;
|
||||
$account->status = Account::STATUS_REGISTERED;
|
||||
|
||||
@@ -21,18 +21,18 @@ class EmailActivationTest extends TestCase {
|
||||
/**
|
||||
* @dataProvider getInstantiateTestCases
|
||||
*/
|
||||
public function testInstantiate(int $type, string $expectedClassType) {
|
||||
public function testInstantiate(int $type, string $expectedClassType): void {
|
||||
$this->assertInstanceOf($expectedClassType, EmailActivation::findOne(['type' => $type]));
|
||||
}
|
||||
|
||||
public function getInstantiateTestCases() {
|
||||
public function getInstantiateTestCases(): iterable {
|
||||
yield [EmailActivation::TYPE_REGISTRATION_EMAIL_CONFIRMATION, confirmations\RegistrationConfirmation::class];
|
||||
yield [EmailActivation::TYPE_FORGOT_PASSWORD_KEY, confirmations\ForgotPassword::class];
|
||||
yield [EmailActivation::TYPE_CURRENT_EMAIL_CONFIRMATION, confirmations\CurrentEmailConfirmation::class];
|
||||
yield [EmailActivation::TYPE_NEW_EMAIL_CONFIRMATION, confirmations\NewEmailConfirmation::class];
|
||||
}
|
||||
|
||||
public function testCanResend() {
|
||||
public function testCanResend(): void {
|
||||
$model = $this->createPartialMock(EmailActivation::class, ['getResendTimeout']);
|
||||
$model->method('getResendTimeout')->willReturn(new DateInterval('PT10M'));
|
||||
|
||||
@@ -45,7 +45,7 @@ class EmailActivationTest extends TestCase {
|
||||
$this->assertEqualsWithDelta(Carbon::now()->subSecond(), $model->canResendAt(), 3);
|
||||
}
|
||||
|
||||
public function testCanResendWithNullTimeout() {
|
||||
public function testCanResendWithNullTimeout(): void {
|
||||
$model = $this->createPartialMock(EmailActivation::class, ['getResendTimeout']);
|
||||
$model->method('getResendTimeout')->willReturn(null);
|
||||
|
||||
@@ -54,7 +54,7 @@ class EmailActivationTest extends TestCase {
|
||||
$this->assertEqualsWithDelta(Carbon::now(), $model->canResendAt(), 3);
|
||||
}
|
||||
|
||||
public function testIsStale() {
|
||||
public function testIsStale(): void {
|
||||
$model = $this->createPartialMock(EmailActivation::class, ['getExpireDuration']);
|
||||
$model->method('getExpireDuration')->willReturn(new DateInterval('PT10M'));
|
||||
|
||||
@@ -65,7 +65,7 @@ class EmailActivationTest extends TestCase {
|
||||
$this->assertTrue($model->isStale());
|
||||
}
|
||||
|
||||
public function testIsStaleWithNullDuration() {
|
||||
public function testIsStaleWithNullDuration(): void {
|
||||
$model = $this->createPartialMock(EmailActivation::class, ['getExpireDuration']);
|
||||
$model->method('getExpireDuration')->willReturn(null);
|
||||
|
||||
|
||||
@@ -13,30 +13,24 @@ class OauthClientQueryTest extends TestCase {
|
||||
];
|
||||
}
|
||||
|
||||
public function testDefaultHideDeletedEntries() {
|
||||
public function testDefaultHideDeletedEntries(): void {
|
||||
/** @var OauthClient[] $clients */
|
||||
$clients = OauthClient::find()->all();
|
||||
$this->assertEmpty(array_filter($clients, function(OauthClient $client) {
|
||||
return (bool)$client->is_deleted === true;
|
||||
}));
|
||||
$this->assertEmpty(array_filter($clients, fn(OauthClient $client): bool => (bool)$client->is_deleted === true));
|
||||
$this->assertNull(OauthClient::findOne('deleted-oauth-client'));
|
||||
}
|
||||
|
||||
public function testAllowFindDeletedEntries() {
|
||||
public function testAllowFindDeletedEntries(): void {
|
||||
/** @var OauthClient[] $clients */
|
||||
$clients = OauthClient::find()->includeDeleted()->all();
|
||||
$this->assertNotEmpty(array_filter($clients, function(OauthClient $client) {
|
||||
return (bool)$client->is_deleted === true;
|
||||
}));
|
||||
$this->assertNotEmpty(array_filter($clients, fn(OauthClient $client): bool => (bool)$client->is_deleted === true));
|
||||
$client = OauthClient::find()
|
||||
->includeDeleted()
|
||||
->andWhere(['id' => 'deleted-oauth-client'])
|
||||
->one();
|
||||
$this->assertInstanceOf(OauthClient::class, $client);
|
||||
$deletedClients = OauthClient::find()->onlyDeleted()->all();
|
||||
$this->assertEmpty(array_filter($deletedClients, function(OauthClient $client) {
|
||||
return (bool)$client->is_deleted === false;
|
||||
}));
|
||||
$this->assertEmpty(array_filter($deletedClients, fn(OauthClient $client): bool => (bool)$client->is_deleted === false));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user