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,7 +6,7 @@ use common\tests\unit\TestCase;
|
||||
|
||||
class EmailHelperTest extends TestCase {
|
||||
|
||||
public function testBuildTo() {
|
||||
public function testBuildTo(): void {
|
||||
$this->assertSame(['mock@ely.by' => 'username'], EmailHelper::buildTo('username', 'mock@ely.by'));
|
||||
}
|
||||
|
||||
|
||||
@@ -6,37 +6,29 @@ namespace common\tests\unit\emails;
|
||||
use common\emails\exceptions\CannotSendEmailException;
|
||||
use common\emails\Template;
|
||||
use common\tests\unit\TestCase;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Yii;
|
||||
use yii\mail\MailerInterface;
|
||||
use yii\mail\MessageInterface;
|
||||
|
||||
class TemplateTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @var Template|\PHPUnit\Framework\MockObject\MockObject $template
|
||||
*/
|
||||
private $template;
|
||||
private Template&MockObject $template;
|
||||
|
||||
/**
|
||||
* @var MailerInterface|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $mailer;
|
||||
private MailerInterface&MockObject $mailer;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $initialFromEmail;
|
||||
private string $initialFromEmail;
|
||||
|
||||
public function testGetters() {
|
||||
public function testGetters(): void {
|
||||
$this->assertSame(['find-me' => 'Ely.by Accounts'], $this->template->getFrom());
|
||||
$this->assertSame([], $this->template->getParams());
|
||||
}
|
||||
|
||||
public function testSend() {
|
||||
public function testSend(): void {
|
||||
$this->runTestForSend(true);
|
||||
}
|
||||
|
||||
public function testNotSend() {
|
||||
public function testNotSend(): void {
|
||||
$this->expectException(CannotSendEmailException::class);
|
||||
$this->runTestForSend(false);
|
||||
}
|
||||
@@ -49,16 +41,15 @@ class TemplateTest extends TestCase {
|
||||
Yii::$app->params['fromEmail'] = 'find-me';
|
||||
}
|
||||
|
||||
protected function _after() {
|
||||
protected function _after(): void {
|
||||
parent::_after();
|
||||
Yii::$app->params['fromEmail'] = $this->initialFromEmail;
|
||||
}
|
||||
|
||||
private function runTestForSend(bool $sendResult) {
|
||||
private function runTestForSend(bool $sendResult): void {
|
||||
$this->template->expects($this->once())->method('getSubject')->willReturn('mock-subject');
|
||||
$this->template->expects($this->once())->method('getView')->willReturn('mock-view');
|
||||
|
||||
/** @var MailerInterface|\PHPUnit\Framework\MockObject\MockObject $message */
|
||||
$message = $this->createMock(MessageInterface::class);
|
||||
$message->expects($this->once())->method('setTo')->with(['to@ely.by' => 'To'])->willReturnSelf();
|
||||
$message->expects($this->once())->method('setFrom')->with(['find-me' => 'Ely.by Accounts'])->willReturnSelf();
|
||||
|
||||
@@ -8,43 +8,32 @@ use common\emails\RendererInterface;
|
||||
use common\emails\TemplateWithRenderer;
|
||||
use common\tests\unit\TestCase;
|
||||
use Exception;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Yii;
|
||||
use yii\mail\MailerInterface;
|
||||
use yii\mail\MessageInterface;
|
||||
|
||||
class TemplateWithRendererTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @var TemplateWithRenderer|\PHPUnit\Framework\MockObject\MockObject $template
|
||||
*/
|
||||
private $template;
|
||||
private TemplateWithRenderer&MockObject $template;
|
||||
|
||||
/**
|
||||
* @var MailerInterface|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $mailer;
|
||||
private MailerInterface&MockObject $mailer;
|
||||
|
||||
/**
|
||||
* @var RendererInterface|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $renderer;
|
||||
private RendererInterface&MockObject $renderer;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $initialFromEmail;
|
||||
private string $initialFromEmail;
|
||||
|
||||
public function testGetLocale() {
|
||||
public function testGetLocale(): void {
|
||||
$this->assertSame('en', $this->template->getLocale());
|
||||
$this->template->setLocale('find me');
|
||||
$this->assertSame('find me', $this->template->getLocale());
|
||||
}
|
||||
|
||||
public function testSend() {
|
||||
public function testSend(): void {
|
||||
$this->runTestForSend();
|
||||
}
|
||||
|
||||
public function testSendWithRenderError() {
|
||||
public function testSendWithRenderError(): void {
|
||||
$renderException = new Exception('find me');
|
||||
try {
|
||||
$this->runTestForSend($renderException);
|
||||
@@ -56,10 +45,10 @@ class TemplateWithRendererTest extends TestCase {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->assertFalse(true, 'no exception was thrown');
|
||||
$this->fail('no exception was thrown');
|
||||
}
|
||||
|
||||
protected function _before() {
|
||||
protected function _before(): void {
|
||||
parent::_before();
|
||||
$this->mailer = $this->createMock(MailerInterface::class);
|
||||
$this->renderer = $this->createMock(RendererInterface::class);
|
||||
@@ -68,12 +57,15 @@ class TemplateWithRendererTest extends TestCase {
|
||||
Yii::$app->params['fromEmail'] = 'find-me';
|
||||
}
|
||||
|
||||
protected function _after() {
|
||||
protected function _after(): void {
|
||||
parent::_after();
|
||||
Yii::$app->params['fromEmail'] = $this->initialFromEmail;
|
||||
}
|
||||
|
||||
private function runTestForSend($renderException = null) {
|
||||
/**
|
||||
* @throws \common\emails\exceptions\CannotRenderEmailException
|
||||
*/
|
||||
private function runTestForSend($renderException = null): void {
|
||||
$renderMethodExpectation = $this->renderer->expects($this->once())->method('render')->with('mock-template', 'mock-locale', []);
|
||||
if ($renderException === null) {
|
||||
$renderMethodExpectation->willReturn('mock-template-contents');
|
||||
@@ -86,7 +78,6 @@ class TemplateWithRendererTest extends TestCase {
|
||||
$this->template->expects($times())->method('getSubject')->willReturn('mock-subject');
|
||||
$this->template->expects($times())->method('getTemplateName')->willReturn('mock-template');
|
||||
|
||||
/** @var MailerInterface|\PHPUnit\Framework\MockObject\MockObject $message */
|
||||
$message = $this->createMock(MessageInterface::class);
|
||||
$message->expects($times())->method('setTo')->with(['to@ely.by' => 'To'])->willReturnSelf();
|
||||
$message->expects($times())->method('setHtmlBody')->with('mock-template-contents')->willReturnSelf();
|
||||
|
||||
@@ -8,25 +8,22 @@ use common\tests\unit\TestCase;
|
||||
use yii\base\InvalidCallException;
|
||||
use yii\mail\MailerInterface;
|
||||
|
||||
class ChangeEmailTest extends TestCase {
|
||||
final class ChangeEmailTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @var ChangeEmail()|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $template;
|
||||
private ChangeEmail $template;
|
||||
|
||||
public function testParams() {
|
||||
public function testParams(): void {
|
||||
$this->template->setKey('mock-key');
|
||||
$params = $this->template->getParams();
|
||||
$this->assertSame('mock-key', $params['key']);
|
||||
}
|
||||
|
||||
public function testInvalidCallOfParams() {
|
||||
public function testInvalidCallOfParams(): void {
|
||||
$this->expectException(InvalidCallException::class);
|
||||
$this->template->getParams();
|
||||
}
|
||||
|
||||
protected function _before() {
|
||||
protected function _before(): void {
|
||||
parent::_before();
|
||||
/** @var MailerInterface|\PHPUnit\Framework\MockObject\MockObject $mailer */
|
||||
$mailer = $this->createMock(MailerInterface::class);
|
||||
|
||||
@@ -10,12 +10,9 @@ use yii\mail\MailerInterface;
|
||||
|
||||
class ConfirmNewEmailTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @var ConfirmNewEmail|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $template;
|
||||
private ConfirmNewEmail $template;
|
||||
|
||||
public function testParams() {
|
||||
public function testParams(): void {
|
||||
$this->template->setUsername('mock-username');
|
||||
$this->template->setKey('mock-key');
|
||||
$params = $this->template->getParams();
|
||||
@@ -26,22 +23,21 @@ class ConfirmNewEmailTest extends TestCase {
|
||||
/**
|
||||
* @dataProvider getInvalidCallsCases
|
||||
*/
|
||||
public function testInvalidCallOfParams(?string $username, ?string $key) {
|
||||
public function testInvalidCallOfParams(?string $username, ?string $key): void {
|
||||
$this->expectException(InvalidCallException::class);
|
||||
$username !== null && $this->template->setUsername($username);
|
||||
$key !== null && $this->template->setKey($key);
|
||||
$this->template->getParams();
|
||||
}
|
||||
|
||||
public function getInvalidCallsCases() {
|
||||
public function getInvalidCallsCases(): iterable {
|
||||
yield [null, null];
|
||||
yield ['value', null];
|
||||
yield [null, 'value'];
|
||||
}
|
||||
|
||||
protected function _before() {
|
||||
protected function _before(): void {
|
||||
parent::_before();
|
||||
/** @var MailerInterface|\PHPUnit\Framework\MockObject\MockObject $mailer */
|
||||
$mailer = $this->createMock(MailerInterface::class);
|
||||
$this->template = new ConfirmNewEmail($mailer);
|
||||
}
|
||||
|
||||
@@ -12,12 +12,9 @@ use yii\mail\MailerInterface;
|
||||
|
||||
class ForgotPasswordEmailTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @var ForgotPasswordEmail|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $template;
|
||||
private ForgotPasswordEmail $template;
|
||||
|
||||
public function testParams() {
|
||||
public function testParams(): void {
|
||||
$this->template->setParams(new ForgotPasswordParams('mock-username', 'mock-code', 'mock-link'));
|
||||
$params = $this->template->getParams();
|
||||
$this->assertSame('mock-username', $params['username']);
|
||||
@@ -25,7 +22,7 @@ class ForgotPasswordEmailTest extends TestCase {
|
||||
$this->assertSame('mock-link', $params['link']);
|
||||
}
|
||||
|
||||
public function testInvalidCallOfParams() {
|
||||
public function testInvalidCallOfParams(): void {
|
||||
$this->expectException(InvalidCallException::class);
|
||||
$this->template->getParams();
|
||||
}
|
||||
|
||||
@@ -12,12 +12,9 @@ use yii\mail\MailerInterface;
|
||||
|
||||
class RegistrationEmailTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @var RegistrationEmail()|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $template;
|
||||
private RegistrationEmail $template;
|
||||
|
||||
public function testParams() {
|
||||
public function testParams(): void {
|
||||
$this->template->setParams(new RegistrationEmailParams('mock-username', 'mock-code', 'mock-link'));
|
||||
$params = $this->template->getParams();
|
||||
$this->assertSame('mock-username', $params['username']);
|
||||
@@ -25,16 +22,14 @@ class RegistrationEmailTest extends TestCase {
|
||||
$this->assertSame('mock-link', $params['link']);
|
||||
}
|
||||
|
||||
public function testInvalidCallOfParams() {
|
||||
public function testInvalidCallOfParams(): void {
|
||||
$this->expectException(InvalidCallException::class);
|
||||
$this->template->getParams();
|
||||
}
|
||||
|
||||
protected function _before() {
|
||||
protected function _before(): void {
|
||||
parent::_before();
|
||||
/** @var MailerInterface|\PHPUnit\Framework\MockObject\MockObject $mailer */
|
||||
$mailer = $this->createMock(MailerInterface::class);
|
||||
/** @var RendererInterface|\PHPUnit\Framework\MockObject\MockObject $renderer */
|
||||
$renderer = $this->createMock(RendererInterface::class);
|
||||
$this->template = new RegistrationEmail($mailer, $renderer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user