AcMailer\Service\MailService::attachMailListener PHP Method

attachMailListener() public method

Attaches a new MailListenerInterface
public attachMailListener ( AcMailer\Event\MailListenerInterface $mailListener, integer $priority = 1 ) : mixed | void
$mailListener AcMailer\Event\MailListenerInterface
$priority integer
return mixed | void
    public function attachMailListener(MailListenerInterface $mailListener, $priority = 1)
    {
        $mailListener->attach($this->getEventManager(), $priority);
        return $this;
    }

Usage Example

 public function testDetachedMailListenerIsNotTriggered()
 {
     $mailListener = new MailListenerMock();
     $this->mailService->attachMailListener($mailListener);
     $this->mailService->detachMailListener($mailListener);
     $result = $this->mailService->send();
     $this->assertTrue($result->isValid());
     $this->assertFalse($mailListener->isOnPreSendCalled());
     $this->assertFalse($mailListener->isOnPostSendCalled());
     $this->assertFalse($mailListener->isOnSendErrorCalled());
 }