AbstractMailListenerTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 44
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A listenersAreRegisteredWhenAttached() 0 15 1
A allMethodsAreEmptyByDefault() 0 8 1
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