diff --git a/src/PHPMailerConfigurator.php b/src/PHPMailerConfigurator.php index 04f6c68..1fd1e85 100644 --- a/src/PHPMailerConfigurator.php +++ b/src/PHPMailerConfigurator.php @@ -7,11 +7,9 @@ use PHPMailer\PHPMailer\DSNConfigurator; use PHPMailer\PHPMailer\PHPMailer; -use function add_action; use function constant; use function defined; use function explode; -use function getenv; /** * Configures PHPMailer via environment variables. @@ -99,7 +97,8 @@ private function configureDKIM(PHPMailer $mailer): void private function getConfig(string $key, $default = null) { - if ($value = getenv($key)) { + $value = $_ENV[$key] ?? null; + if ($value !== null) { return $value; } diff --git a/tests/PHPMailerConfiguratorTest.php b/tests/PHPMailerConfiguratorTest.php index 9f8cc0b..49c9f2f 100644 --- a/tests/PHPMailerConfiguratorTest.php +++ b/tests/PHPMailerConfiguratorTest.php @@ -8,6 +8,7 @@ use PHPUnit\Framework\TestCase; use PopArtDesign\WordPressMailerDSN\PHPMailerConfigurator; + /** * @covers PHPMailerConfigurator * @runTestsInSeparateProcesses @@ -20,7 +21,7 @@ public function testConfiguresUsingMailerDsnEnv() $configurator = new PHPMailerConfigurator(); $mailer = new PHPMailer(); - putenv('MAILER_DSN=smtps://pop:art@popartdesign.ru:587?SMTPDebug=3&Timeout=1000'); + $_ENV['MAILER_DSN'] = 'smtps://pop:art@popartdesign.ru:587?SMTPDebug=3&Timeout=1000'; $configurator->configure($mailer); @@ -51,7 +52,7 @@ public function testGivesPreferenceToEnvsOverConstants() $configurator = new PHPMailerConfigurator(); $mailer = new PHPMailer(); - putenv('MAILER_DSN=smtps://pop:art@popartdesign.ru:587?SMTPDebug=3&Timeout=1000'); + $_ENV['MAILER_DSN'] = 'smtps://pop:art@popartdesign.ru:587?SMTPDebug=3&Timeout=1000'; define('MAILER_DSN', 'sendmail://localhost?Sendmail=/usr/sbin/sendmail%20-oi%20-t'); $configurator->configure($mailer); @@ -64,8 +65,8 @@ public function testConfiguresDebugUsingEnvs() $configurator = new PHPMailerConfigurator(); $mailer = new PHPMailer(); - putenv('MAILER_DEBUG=3'); - putenv('MAILER_DEBUG_OUTPUT=error_log'); + $_ENV['MAILER_DEBUG'] = 3; + $_ENV['MAILER_DEBUG_OUTPUT'] = 'error_log'; $configurator->configure($mailer); @@ -78,9 +79,9 @@ public function testConfiguresCommonUsingEnvs() $configurator = new PHPMailerConfigurator(); $mailer = new PHPMailer(); - putenv('MAILER_FROM=oleg-voronkovich@yandex.ru'); - putenv('MAILER_FROM_NAME=Oleg Voronkovich'); - putenv('MAILER_SENDER=no-reply@popartdesign.ru'); + $_ENV['MAILER_FROM'] = 'oleg-voronkovich@yandex.ru'; + $_ENV['MAILER_FROM_NAME'] = 'Oleg Voronkovich'; + $_ENV['MAILER_SENDER'] = 'no-reply@popartdesign.ru'; $configurator->configure($mailer); @@ -94,12 +95,12 @@ public function testConfiguresDkimUsingEnvs() $configurator = new PHPMailerConfigurator(); $mailer = new PHPMailer(); - putenv('MAILER_DKIM_PRIVATE=/tmp/private.key'); - putenv('MAILER_DKIM_PRIVATE_STRING=private'); - putenv('MAILER_DKIM_PASSPHRASE=secret'); - putenv('MAILER_DKIM_SELECTOR=mailer'); - putenv('MAILER_DKIM_DOMAIN=popartdesign.ru'); - putenv('MAILER_DKIM_IDENTITY=no-reply@popartdesign.ru'); + $_ENV['MAILER_DKIM_PRIVATE'] = '/tmp/private.key'; + $_ENV['MAILER_DKIM_PRIVATE_STRING'] = 'private'; + $_ENV['MAILER_DKIM_PASSPHRASE'] = 'secret'; + $_ENV['MAILER_DKIM_SELECTOR'] = 'mailer'; + $_ENV['MAILER_DKIM_DOMAIN'] = 'popartdesign.ru'; + $_ENV['MAILER_DKIM_IDENTITY'] = 'no-reply@popartdesign.ru'; $configurator->configure($mailer); @@ -118,10 +119,10 @@ public function testConfiguresDkimDomainAndIdentityWithDefaultValues() $mailer->From = 'no-reply@popartdesign.ru'; - putenv('MAILER_DKIM_PRIVATE=/tmp/private.key'); - putenv('MAILER_DKIM_PRIVATE_STRING=private'); - putenv('MAILER_DKIM_PASSPHRASE=secret'); - putenv('MAILER_DKIM_SELECTOR=mailer'); + $_ENV['MAILER_DKIM_PRIVATE'] = '/tmp/private.key'; + $_ENV['MAILER_DKIM_PRIVATE_STRING'] = 'private'; + $_ENV['MAILER_DKIM_PASSPHRASE'] = 'secret'; + $_ENV['MAILER_DKIM_SELECTOR'] = 'mailer'; $configurator->configure($mailer);