[TASK] Make MailerTest notice free 65/56265/4
authorSascha Löffler <lsascha@gmail.com>
Fri, 16 Mar 2018 22:17:32 +0000 (23:17 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sat, 17 Mar 2018 11:26:37 +0000 (12:26 +0100)
Resolves: #84386
Releases: master
Change-Id: I4c9730cb8dfc6f787c9201d7dbdcead73869958d
Reviewed-on: https://review.typo3.org/56265
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Sascha Löffler <lsascha@gmail.com>
Tested-by: Sascha Löffler <lsascha@gmail.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Classes/Mail/TransportFactory.php
typo3/sysext/core/Tests/Unit/Mail/MailerTest.php

index 9c24259..1bd203b 100644 (file)
@@ -53,22 +53,30 @@ class TransportFactory implements SingletonInterface
                 break;
             case 'smtp':
                 // Get settings to be used when constructing the transport object
-                list($host, $port) = preg_split('/:/', $mailSettings['transport_smtp_server'] ?? '');
+                if (isset($mailSettings['transport_smtp_server']) && strpos($mailSettings['transport_smtp_server'], ':') > 0) {
+                    $parts = GeneralUtility::trimExplode(':', $mailSettings['transport_smtp_server'], true);
+                    $host = $parts[0];
+                    $port = $parts[1] ?? null;
+                } else {
+                    $host = (string)$mailSettings['transport_smtp_server'] ?? null;
+                    $port = null;
+                }
+
                 if ($host === '') {
                     throw new Exception('$GLOBALS[\'TYPO3_CONF_VARS\'][\'MAIL\'][\'transport_smtp_server\'] needs to be set when transport is set to "smtp".', 1291068606);
                 }
                 if ($port === null || $port === '') {
                     $port = 25;
                 }
-                $useEncryption = $mailSettings['transport_smtp_encrypt'] ?: null;
+                $useEncryption = $mailSettings['transport_smtp_encrypt'] ?? null;
                 // Create our transport
                 $transport = \Swift_SmtpTransport::newInstance($host, $port, $useEncryption);
                 // Need authentication?
-                $username = $mailSettings['transport_smtp_username'];
+                $username = (string)($mailSettings['transport_smtp_username'] ?? '');
                 if ($username !== '') {
                     $transport->setUsername($username);
                 }
-                $password = $mailSettings['transport_smtp_password'];
+                $password = (string)($mailSettings['transport_smtp_password'] ?? '');
                 if ($password !== '') {
                     $transport->setPassword($password);
                 }
index 89eb32f..678e2ea 100644 (file)
@@ -15,26 +15,25 @@ namespace TYPO3\CMS\Core\Tests\Unit\Mail;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Controller\ErrorPageController;
+use TYPO3\CMS\Core\Exception;
+use TYPO3\CMS\Core\Mail\Mailer;
 use TYPO3\CMS\Core\Tests\Unit\Mail\Fixtures\FakeTransportFixture;
+use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
 
 /**
  * Testcase for the TYPO3\CMS\Core\Mail\Mailer class.
  */
-class MailerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
+class MailerTest extends UnitTestCase
 {
     /**
-     * Subject is not notice free, disable E_NOTICES
-     */
-    protected static $suppressNotices = true;
-
-    /**
-     * @var \TYPO3\CMS\Core\Mail\Mailer
+     * @var Mailer
      */
     protected $subject;
 
     protected function setUp()
     {
-        $this->subject = $this->getMockBuilder(\TYPO3\CMS\Core\Mail\Mailer::class)
+        $this->subject = $this->getMockBuilder(Mailer::class)
             ->setMethods(['emitPostInitializeMailerSignal'])
             ->disableOriginalConstructor()
             ->getMock();
@@ -76,7 +75,7 @@ class MailerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
             'smtp but no host' => [['transport' => 'smtp']],
             'sendmail but no command' => [['transport' => 'sendmail']],
             'mbox but no file' => [['transport' => 'mbox']],
-            'no instance of Swift_Transport' => [['transport' => \TYPO3\CMS\Core\Controller\ErrorPageController::class]]
+            'no instance of Swift_Transport' => [['transport' => ErrorPageController::class]]
         ];
     }
 
@@ -87,7 +86,7 @@ class MailerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
      */
     public function wrongConfigurationThrowsException($settings)
     {
-        $this->expectException(\TYPO3\CMS\Core\Exception::class);
+        $this->expectException(Exception::class);
         $this->expectExceptionCode(1291068569);
 
         $this->subject->injectMailSettings($settings);