Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
voronkovich committed Sep 10, 2024
1 parent 827e653 commit 0ace2c1
Showing 1 changed file with 52 additions and 14 deletions.
66 changes: 52 additions & 14 deletions tests/PHPMailerConfiguratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use PHPUnit\Framework\TestCase;
use PopArtDesign\WordPressMailerDSN\PHPMailerConfigurator;


/**
* @covers PHPMailerConfigurator
* @runTestsInSeparateProcesses
Expand Down Expand Up @@ -47,19 +46,6 @@ public function testConfiguresUsingMailerDsnConstant()
$this->assertEquals('/usr/sbin/sendmail -oi -t', $mailer->Sendmail);
}

public function testGivesPreferenceToEnvsOverConstants()
{
$configurator = new PHPMailerConfigurator();
$mailer = new PHPMailer();

$_SERVER['MAILER_DSN'] = 'smtps://pop:[email protected]:587?SMTPDebug=3&Timeout=1000';
define('MAILER_DSN', 'sendmail://localhost?Sendmail=/usr/sbin/sendmail%20-oi%20-t');

$configurator->configure($mailer);

$this->assertEquals('smtp', $mailer->Mailer);
}

public function testConfiguresDebugUsingEnvs()
{
$configurator = new PHPMailerConfigurator();
Expand Down Expand Up @@ -129,4 +115,56 @@ public function testConfiguresDkimDomainAndIdentityWithDefaultValues()
$this->assertEquals('[email protected]', $mailer->DKIM_identity);
$this->assertEquals('popartdesign.ru', $mailer->DKIM_domain);
}

public function testGivesPreferenceToEnvsOverConstants()
{
$configurator = new PHPMailerConfigurator();
$mailer = new PHPMailer();

$_SERVER['MAILER_DSN'] = 'smtps://pop:[email protected]:587?SMTPDebug=3&Timeout=1000';
define('MAILER_DSN', 'sendmail://localhost?Sendmail=/usr/sbin/sendmail%20-oi%20-t');

$configurator->configure($mailer);

$this->assertEquals('smtp', $mailer->Mailer);
}

public function testGivesPreferenceToServerSuperglobalOverEnvAndGetenv()
{
$configurator = new PHPMailerConfigurator();
$mailer = new PHPMailer();

$_SERVER['MAILER_DEBUG'] = 1;
$_ENV['MAILER_DEBUG'] = 2;
putenv('MAILER_DEBUG=3');

$configurator->configure($mailer);

$this->assertEquals(1, $mailer->SMTPDebug);
}

public function testUsesEnvSuperglobalIfServerIsNotSet()
{
$configurator = new PHPMailerConfigurator();
$mailer = new PHPMailer();

$_ENV['MAILER_DEBUG'] = 1;
putenv('MAILER_DEBUG=2');

$configurator->configure($mailer);

$this->assertEquals(1, $mailer->SMTPDebug);
}

public function testUsesGetenvAsFallback()
{
$configurator = new PHPMailerConfigurator();
$mailer = new PHPMailer();

putenv('MAILER_DEBUG=1');

$configurator->configure($mailer);

$this->assertEquals(1, $mailer->SMTPDebug);
}
}

0 comments on commit 0ace2c1

Please sign in to comment.