/** * Configures specific transport options * @param TransportInterface $transport * @param MailOptions $mailOptions */ protected function setupSpecificConfig(TransportInterface $transport, MailOptions $mailOptions) { if ($transport instanceof Smtp) { $connConfig = array('username' => $mailOptions->getSmtpUser(), 'password' => $mailOptions->getSmtpPassword()); // Check if SSL should be used if ($mailOptions->getSsl() !== false) { $connConfig['ssl'] = $mailOptions->getSsl(); } // Set SMTP transport options $transport->setOptions(new SmtpOptions(array('host' => $mailOptions->getServer(), 'port' => $mailOptions->getPort(), 'connection_class' => $mailOptions->getConnectionClass(), 'connection_config' => $connConfig))); } elseif ($transport instanceof File) { $transport->setOptions(new FileOptions(array('path' => $mailOptions->getFilePath(), 'callback' => $mailOptions->getFileCallback()))); } }
/** * Attaches the preconfigured mail listeners to the mail service * * @param MailListenerAwareInterface $service * @param ServiceLocatorInterface $sm * @throws InvalidArgumentException */ protected function attachMailListeners(MailListenerAwareInterface $service, ServiceLocatorInterface $sm) { $listeners = $this->mailOptions->getMailListeners(); foreach ($listeners as $listener) { // Try to fetch the listener from the ServiceManager or lazily create an instance if (is_string($listener) && $sm->has($listener)) { $listener = $sm->get($listener); } elseif (is_string($listener) && class_exists($listener)) { $listener = new $listener(); } // At this point, the listener should be an instance of MailListenerInterface, otherwise it is invalid if (!$listener instanceof MailListenerInterface) { throw new InvalidArgumentException(sprintf('Provided listener of type "%s" is not valid. ' . 'Expected "string" or "AcMailer\\Listener\\MailListenerInterface"', is_object($listener) ? get_class($listener) : gettype($listener))); } $service->attachMailListener($listener); } }
/** * @expectedException InvalidArgumentException */ public function testInvalidAttachmentsThrowException() { $this->mailOptions->setAttachments(null); }
public function testSetMailListeners() { $this->assertCount(0, $this->mailOptions->getMailListeners()); $this->assertSame($this->mailOptions, $this->mailOptions->setMailListeners([1, 2, 3])); $this->assertCount(3, $this->mailOptions->getMailListeners()); }
public function testSetRenderer() { $this->assertEquals('mailviewrenderer', $this->mailOptions->getRenderer()); $this->assertSame($this->mailOptions, $this->mailOptions->setRenderer('foo')); $this->assertEquals('foo', $this->mailOptions->getRenderer()); }