@@ -45,4 +45,49 @@ public function test_mail_gets_mapped() : void
4545 $ this ->assertEquals ('25 ' , getenv ('MAIL_PORT ' ));
4646 $ this ->assertEquals ('0 ' , getenv ('MAIL_ENCRYPTION ' ));
4747 }
48+
49+ /**
50+ * Test if the project has been instructed to disable Platform's own SMTP proxy
51+ *
52+ * @return void
53+ */
54+ public function test_disabled_mail () : void
55+ {
56+ $ smtpHost = 'smtp.external-service.com ' ;
57+ $ smtpPort = '587 ' ;
58+ $ smtpMailer = 'sendmail ' ;
59+ $ smtpEncyption = 'tls ' ;
60+
61+ putenv ('PLATFORM_APPLICATION_NAME=test ' );
62+ putenv ('PLATFORM_ENVIRONMENT=test ' );
63+ putenv ('PLATFORM_PROJECT_ENTROPY=test ' );
64+ putenv ('MAIL_HOST= ' . $ smtpHost );
65+ putenv ('MAIL_MAILER= ' . $ smtpMailer );
66+ putenv ('MAIL_PORT= ' . $ smtpPort );
67+ putenv ('MAIL_ENCRYPTION= ' . $ smtpEncyption );
68+ $ this ->loadDummyRoutes ();
69+
70+ /**
71+ * https://support.platform.sh/hc/en-us/articles/12055076033810-Email-SMTP-sending-details
72+ * There is mixed information on the value of PLATFORM_SMTP_HOST the above support ticket
73+ * states When outgoing emails are off, the variable is empty
74+ * Debugging on an instance shows it's set to false.
75+ *
76+ * These assertions test both senarios
77+ */
78+ putenv (sprintf ('PLATFORM_SMTP_HOST=%s ' , '' ));
79+ mapPlatformShEnvironment ();
80+ $ this ->assertEquals ($ smtpHost , getenv ('MAIL_HOST ' ));
81+ $ this ->assertEquals ($ smtpMailer , getenv ('MAIL_MAILER ' ));
82+ $ this ->assertEquals ($ smtpPort , getenv ('MAIL_PORT ' ));
83+ $ this ->assertEquals ($ smtpEncyption , getenv ('MAIL_ENCRYPTION ' ));
84+
85+ putenv (sprintf ('PLATFORM_SMTP_HOST=%s ' , false ));
86+ mapPlatformShEnvironment ();
87+ $ this ->assertEquals ($ smtpHost , getenv ('MAIL_HOST ' ));
88+ $ this ->assertEquals ($ smtpMailer , getenv ('MAIL_MAILER ' ));
89+ $ this ->assertEquals ($ smtpPort , getenv ('MAIL_PORT ' ));
90+ $ this ->assertEquals ($ smtpEncyption , getenv ('MAIL_ENCRYPTION ' ));
91+
92+ }
4893}
0 commit comments