Skip to content

Commit 14a519c

Browse files
committed
Fix email debug
1 parent 648c8b5 commit 14a519c

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

src/Mailer/Mailer.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ class Mailer extends CakeMailer {
3434
*/
3535
protected $localeBefore;
3636

37+
/**
38+
* @var array
39+
*/
40+
protected $debug = [];
41+
3742
/**
3843
* Magic method to forward method class to Message instance.
3944
*
@@ -143,11 +148,33 @@ protected function detectPrimaryLocale(): ?string {
143148
return $primaryLocale;
144149
}
145150

151+
/**
152+
* Render content and send email using configured transport.
153+
*
154+
* @param string $content Content.
155+
* @return array
156+
* @psalm-return array{headers: string, message: string}
157+
*/
158+
public function deliver(string $content = '')
159+
{
160+
$this->debug = parent::deliver($content);
161+
162+
return $this->debug;
163+
}
164+
165+
/**
166+
* @return array
167+
*/
168+
public function getDebug(): array{
169+
return $this->debug;
170+
}
171+
146172
/**
147173
* @return $this
148174
*/
149175
public function reset() {
150176
$this->locale = null;
177+
$this->debug = [];
151178

152179
return parent::reset();
153180
}

tests/TestCase/Mailer/MailerTest.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
use TestApp\Mailer\TestMailer;
1212
use Tools\Mailer\Mailer;
1313

14-
/**
15-
* EmailTest class
16-
*/
1714
class MailerTest extends TestCase {
1815

1916
/**
@@ -32,7 +29,6 @@ public function setUp(): void {
3229
I18n::setLocale(I18n::getDefaultLocale());
3330
Configure::write('Config.defaultLocale', 'deu');
3431

35-
//Mailer::setConfig('test');
3632
TransportFactory::setConfig('debug', [
3733
'className' => 'Debug',
3834
]);
@@ -124,7 +120,7 @@ public function testDeliverLocaleCustom(): void {
124120
public function testAddEmbeddedAttachmentSend() {
125121
$file = Plugin::path('Tools') . 'tests' . DS . 'test_files' . DS . 'img' . DS . 'hotel.png';
126122

127-
Configure::write('debug', 0);
123+
//Configure::write('debug', 0);
128124
$this->mailer->setEmailFormat('both');
129125
$this->mailer->setTo(Configure::read('Config.adminEmail'));
130126
$cid = $this->mailer->addEmbeddedAttachment($file);
@@ -147,11 +143,14 @@ public function testAddEmbeddedAttachmentSend() {
147143
$text = trim(strip_tags($html));
148144
$this->mailer->setViewVars(compact('text', 'html'));
149145

150-
$res = $this->mailer->send();
151-
Configure::write('debug', 2);
146+
$res = $this->mailer->deliver();
147+
//Configure::write('debug', 2);
152148

153-
//$this->assertEquals('', $this->mailer->getError());
154149
$this->assertTrue((bool)$res);
150+
151+
$debug = $this->mailer->getDebug();
152+
//FIXME
153+
//$this->assertTextContains('test_embedded_default', $debug['message']);
155154
}
156155

157156
/**

0 commit comments

Comments
 (0)