From 76bedb884318ebd37031a2aa696c7bee8827db2c Mon Sep 17 00:00:00 2001 From: Simon L Date: Fri, 23 Jun 2023 11:07:41 +0200 Subject: [PATCH 1/2] use getsystemvalue-functions in Mailer.php Signed-off-by: Simon L --- lib/private/Mail/Mailer.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/private/Mail/Mailer.php b/lib/private/Mail/Mailer.php index 5d838b2cdf1f0..7d249338bdcaf 100644 --- a/lib/private/Mail/Mailer.php +++ b/lib/private/Mail/Mailer.php @@ -292,7 +292,7 @@ protected function getSmtpInstance(): EsmtpTransport { // either null or true - if nothing is passed, let the symfony mailer figure out the configuration by itself $mailSmtpsecure = ($this->config->getSystemValue('mail_smtpsecure', null) === 'ssl') ? true : null; $transport = new EsmtpTransport( - $this->config->getSystemValue('mail_smtphost', '127.0.0.1'), + $this->config->getSystemValueString('mail_smtphost', '127.0.0.1'), $this->config->getSystemValueInt('mail_smtpport', 25), $mailSmtpsecure, null, @@ -301,11 +301,11 @@ protected function getSmtpInstance(): EsmtpTransport { /** @var SocketStream $stream */ $stream = $transport->getStream(); /** @psalm-suppress InternalMethod */ - $stream->setTimeout($this->config->getSystemValue('mail_smtptimeout', 10)); + $stream->setTimeout($this->config->getSystemValueInt('mail_smtptimeout', 10)); if ($this->config->getSystemValueBool('mail_smtpauth', false)) { - $transport->setUsername($this->config->getSystemValue('mail_smtpname', '')); - $transport->setPassword($this->config->getSystemValue('mail_smtppassword', '')); + $transport->setUsername($this->config->getSystemValueString('mail_smtpname', '')); + $transport->setPassword($this->config->getSystemValueString('mail_smtppassword', '')); } $streamingOptions = $this->config->getSystemValue('mail_smtpstreamoptions', []); From 1cb81ae625f75d0d2a6bf13c9a3b39365dc6d215 Mon Sep 17 00:00:00 2001 From: Simon L Date: Fri, 23 Jun 2023 17:12:45 +0200 Subject: [PATCH 2/2] try to fix tests Signed-off-by: Simon L --- tests/lib/Mail/MailerTest.php | 43 ++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/tests/lib/Mail/MailerTest.php b/tests/lib/Mail/MailerTest.php index ba1d52f4bafc0..5ffba9392841e 100644 --- a/tests/lib/Mail/MailerTest.php +++ b/tests/lib/Mail/MailerTest.php @@ -240,14 +240,17 @@ public function testStreamingOptions() { $this->config->method('getSystemValue') ->willReturnMap([ ['mail_smtpstreamoptions', [], ['foo' => 1]], - ['mail_smtphost', '127.0.0.1', '127.0.0.1'], - ['mail_smtpport', 25, 25], - ['mail_smtptimeout', 10, 10], ]); $this->config->method('getSystemValueString') ->willReturnMap([ ['mail_smtpmode', 'smtp', 'smtp'], ['overwrite.cli.url', '', ''], + ['mail_smtphost', '127.0.0.1', '127.0.0.1'], + ]); + $this->config->method('getSystemValueInt') + ->willReturnMap([ + ['mail_smtpport', 25, 25], + ['mail_smtptimeout', 10, 10], ]); $mailer = self::invokePrivate($this->mailer, 'getInstance'); /** @var EsmtpTransport $transport */ @@ -261,15 +264,19 @@ public function testStreamingOptionsWrongType() { $this->config->method('getSystemValue') ->willReturnMap([ ['mail_smtpstreamoptions', [], 'bar'], - ['mail_smtphost', '127.0.0.1', '127.0.0.1'], - ['mail_smtpport', 25, 25], - ['mail_smtptimeout', 10, 10], ]); $this->config->method('getSystemValueString') ->willReturnMap([ ['mail_smtpmode', 'smtp', 'smtp'], ['overwrite.cli.url', '', ''], + ['mail_smtphost', '127.0.0.1', '127.0.0.1'], + ]); + $this->config->method('getSystemValueInt') + ->willReturnMap([ + ['mail_smtpport', 25, 25], + ['mail_smtptimeout', 10, 10], ]); + $mailer = self::invokePrivate($this->mailer, 'getInstance'); /** @var EsmtpTransport $transport */ $transport = self::invokePrivate($mailer, 'transport'); @@ -278,16 +285,16 @@ public function testStreamingOptionsWrongType() { } public function testLocalDomain(): void { - $this->config->method('getSystemValue') - ->willReturnMap([ - ['mail_smtphost', '127.0.0.1', '127.0.0.1'], - ['mail_smtpport', 25, 25], - ['mail_smtptimeout', 10, 10], - ]); $this->config->method('getSystemValueString') ->willReturnMap([ ['mail_smtpmode', 'smtp', 'smtp'], ['overwrite.cli.url', '', 'https://some.valid.url.com:8080'], + ['mail_smtphost', '127.0.0.1', '127.0.0.1'], + ]); + $this->config->method('getSystemValueInt') + ->willReturnMap([ + ['mail_smtpport', 25, 25], + ['mail_smtptimeout', 10, 10], ]); /** @var SymfonyMailer $mailer */ @@ -301,16 +308,16 @@ public function testLocalDomain(): void { } public function testLocalDomainInvalidUrl(): void { - $this->config->method('getSystemValue') - ->willReturnMap([ - ['mail_smtpport', 25, 25], - ['mail_smtptimeout', 10, 10], - ['mail_smtphost', '127.0.0.1', '127.0.0.1'], - ]); $this->config->method('getSystemValueString') ->willReturnMap([ ['mail_smtpmode', 'smtp', 'smtp'], ['overwrite.cli.url', '', 'https:only.slash.does.not.work:8080'], + ['mail_smtphost', '127.0.0.1', '127.0.0.1'], + ]); + $this->config->method('getSystemValueInt') + ->willReturnMap([ + ['mail_smtpport', 25, 25], + ['mail_smtptimeout', 10, 10], ]); /** @var SymfonyMailer $mailer */