1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace AcMailerTest\Event; |
5
|
|
|
|
6
|
|
|
use AcMailer\Event\AbstractMailListener; |
7
|
|
|
use AcMailer\Event\MailEvent; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
use Zend\EventManager\EventManagerInterface; |
10
|
|
|
|
11
|
|
|
class AbstractMailListenerTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var AbstractMailListener |
15
|
|
|
*/ |
16
|
|
|
private $mailListener; |
17
|
|
|
|
18
|
|
|
public function setUp() |
19
|
|
|
{ |
20
|
|
|
$this->mailListener = new class extends AbstractMailListener { |
21
|
|
|
}; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @test |
26
|
|
|
*/ |
27
|
|
|
public function listenersAreRegisteredWhenAttached() |
28
|
|
|
{ |
29
|
|
|
$em = $this->prophesize(EventManagerInterface::class); |
30
|
|
|
$priority = 3; |
31
|
|
|
|
32
|
|
|
$attachPre = $em->attach(MailEvent::EVENT_MAIL_PRE_SEND, [$this->mailListener, 'onPreSend'], $priority); |
33
|
|
|
$attachPost = $em->attach(MailEvent::EVENT_MAIL_POST_SEND, [$this->mailListener, 'onPostSend'], $priority); |
34
|
|
|
$attachError = $em->attach(MailEvent::EVENT_MAIL_SEND_ERROR, [$this->mailListener, 'onSendError'], $priority); |
35
|
|
|
|
36
|
|
|
$this->mailListener->attach($em->reveal(), $priority); |
37
|
|
|
|
38
|
|
|
$attachPre->shouldHaveBeenCalled(); |
39
|
|
|
$attachPost->shouldHaveBeenCalled(); |
40
|
|
|
$attachError->shouldHaveBeenCalled(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @test |
45
|
|
|
*/ |
46
|
|
|
public function allMethodsAreEmptyByDefault() |
47
|
|
|
{ |
48
|
|
|
$event = $this->prophesize(MailEvent::class); |
49
|
|
|
|
50
|
|
|
$this->assertNull($this->mailListener->onPreSend($event->reveal())); |
51
|
|
|
$this->assertNull($this->mailListener->onPostSend($event->reveal())); |
52
|
|
|
$this->assertNull($this->mailListener->onSendError($event->reveal())); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|