Skip to content

Commit

Permalink
add dmumy key for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lekoala committed Jul 26, 2023
1 parent 3778f7c commit b5d7589
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions tests/MandrillTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use SilverStripe\Core\Environment;
use SilverStripe\Dev\SapphireTest;
use LeKoala\Mandrill\MandrillHelper;
use Mandrill;
use SilverStripe\Control\Email\Email;
use SilverStripe\Core\Injector\Injector;
use Symfony\Component\Mailer\Mailer;
Expand All @@ -19,11 +20,18 @@
class MandrillTest extends SapphireTest
{
protected $testMailer;
protected $isDummy = false;

protected function setUp(): void
{
parent::setUp();

// add dummy api key
if (!MandrillHelper::getAPIKey()) {
$this->isDummy = true;
Environment::setEnv('MANDRILL_API_KEY', 'dummy');
}

$this->testMailer = Injector::inst()->get(MailerInterface::class);
}

Expand All @@ -36,10 +44,6 @@ protected function tearDown(): void

public function testSetup()
{
if (!MandrillHelper::getApiKey()) {
return $this->markTestIncomplete("No api key set for test");
}

$inst = MandrillHelper::registerTransport();
$mailer = MandrillHelper::getMailer();
$instClass = get_class($inst);
Expand All @@ -58,7 +62,7 @@ public function testSending()
$email->setSubject('Test email');
$email->setBody("Body of my email");

if (!$test_from || !$test_to) {
if (!$test_from || !$test_to || $this->isDummy) {
$test_to = "example@localhost";
$test_from = "sender@localhost";
// don't try to send it for real
Expand Down

0 comments on commit b5d7589

Please sign in to comment.