/**
  * {@inheritdoc}
  */
 public function create($type, array $body)
 {
     $message = new Message();
     $message->setType($type);
     $message->setBody($body);
     $message->setState(MessageInterface::STATE_OPEN);
     return $message;
 }
 public function testSendEMailWithCustomConfig()
 {
     $mock = $this->getMockBuilder(SystemMailer::class)->disableOriginalConstructor()->getMock();
     $user = new User(new Credentials('Ma27', '123456'), new UserDetails('*****@*****.**', new \DateTime(), new \DateTime()));
     $mock->expects($this->once())->method('send')->with('App:custom', ['user' => $user]);
     $model = new Message();
     $model->setBody(['user' => $user, 'config_path' => 'App:custom']);
     $mailer = new Mailer($mock);
     $mailer->process(new ConsumerEvent($model));
 }
 public function testCreate()
 {
     $testBackend = $this->getMockBuilder('Sonata\\NotificationBundle\\Backend\\MessageManagerBackend')->disableOriginalConstructor()->getMock();
     $testBackend->expects($this->once())->method('setDispatcher');
     $message = new Message();
     $message->setType("test");
     $message->setBody(array());
     $testBackend->expects($this->once())->method('create')->will($this->returnValue($message));
     $mMgr = $this->getMock('Sonata\\NotificationBundle\\Model\\MessageManagerInterface');
     $mMgrBackend = new MessageManagerBackendDispatcher($mMgr, array(), '', array(array('types' => array('test'), 'backend' => $testBackend)));
     $this->assertEquals($message, $mMgrBackend->create("test", array()));
 }
 /**
  * Tests the sendEmail method.
  */
 public function testSendEmail()
 {
     $message = new Message();
     $message->setBody(array('subject' => 'subject', 'from' => array('email' => '*****@*****.**', 'name' => 'nameFrom'), 'to' => array('*****@*****.**', '*****@*****.**' => 'nameTo2'), 'replyTo' => array('*****@*****.**', '*****@*****.**' => 'nameReplyTo2'), 'message' => array('text' => 'message text', 'html' => 'message html')));
     $mail = $this->getMockBuilder('Swift_Message')->disableOriginalConstructor()->getMock();
     $mail->expects($this->once())->method('setSubject')->with($this->equalTo('subject'))->willReturnSelf();
     $mail->expects($this->once())->method('setFrom')->with($this->equalTo(array('*****@*****.**' => 'nameFrom')))->willReturnSelf();
     $mail->expects($this->once())->method('setTo')->with($this->equalTo(array('*****@*****.**', '*****@*****.**' => 'nameTo2')))->willReturnSelf();
     $mail->expects($this->once())->method('setReplyTo')->with($this->equalTo(array('*****@*****.**', '*****@*****.**' => 'nameReplyTo2')))->willReturnSelf();
     $mail->expects($this->exactly(2))->method('addPart')->withConsecutive(array($this->equalTo('message text'), $this->equalTo('text/plain')), array($this->equalTo('message html'), $this->equalTo('text/html')))->willReturnSelf();
     $this->mailer->expects($this->once())->method('createMessage')->will($this->returnValue($mail));
     $method = new \ReflectionMethod($this->consumer, 'sendEmail');
     $method->setAccessible(true);
     $method->invoke($this->consumer, $message);
 }