1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sonata package. |
5
|
|
|
* |
6
|
|
|
* (c) Thomas Rabaix <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sonata\NotificationBundle\Tests\Consumer; |
13
|
|
|
|
14
|
|
|
use Sonata\NotificationBundle\Consumer\SwiftMailerConsumer; |
15
|
|
|
use Sonata\NotificationBundle\Model\Message; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Tests the SwiftMailerConsumer. |
19
|
|
|
*/ |
20
|
|
|
class SwiftMailerConsumerTest extends \PHPUnit_Framework_TestCase |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var SwiftMailerConsumer |
24
|
|
|
*/ |
25
|
|
|
private $consumer; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var \Swift_Mailer |
29
|
|
|
*/ |
30
|
|
|
private $mailer; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Initializes some dependencies used by tests. |
34
|
|
|
*/ |
35
|
|
|
protected function setUp() |
36
|
|
|
{ |
37
|
|
|
$this->mailer = $this->getMockBuilder('Swift_Mailer') |
38
|
|
|
->disableOriginalConstructor() |
39
|
|
|
->getMock(); |
40
|
|
|
|
41
|
|
|
$this->consumer = new SwiftMailerConsumer($this->mailer); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Tests the sendEmail method. |
46
|
|
|
*/ |
47
|
|
|
public function testSendEmail() |
48
|
|
|
{ |
49
|
|
|
$message = new Message(); |
50
|
|
|
$message->setBody(array( |
51
|
|
|
'subject' => 'subject', |
52
|
|
|
'from' => array( |
53
|
|
|
'email' => '[email protected]', |
54
|
|
|
'name' => 'nameFrom', |
55
|
|
|
), |
56
|
|
|
'to' => array( |
57
|
|
|
'[email protected]', |
58
|
|
|
'[email protected]' => 'nameTo2', |
59
|
|
|
), |
60
|
|
|
'replyTo' => array( |
61
|
|
|
'[email protected]', |
62
|
|
|
'[email protected]' => 'nameReplyTo2', |
63
|
|
|
), |
64
|
|
|
'message' => array( |
65
|
|
|
'text' => 'message text', |
66
|
|
|
'html' => 'message html', |
67
|
|
|
), |
68
|
|
|
)); |
69
|
|
|
|
70
|
|
|
$mail = $this->getMockBuilder('Swift_Message')->disableOriginalConstructor()->getMock(); |
71
|
|
|
$mail->expects($this->once())->method('setSubject')->with($this->equalTo('subject'))->willReturnSelf(); |
72
|
|
|
$mail->expects($this->once())->method('setFrom')->with($this->equalTo(array('[email protected]' => 'nameFrom')))->willReturnSelf(); |
73
|
|
|
$mail->expects($this->once())->method('setTo')->with($this->equalTo(array('[email protected]', '[email protected]' => 'nameTo2')))->willReturnSelf(); |
74
|
|
|
$mail->expects($this->once())->method('setReplyTo')->with($this->equalTo(array('[email protected]', '[email protected]' => 'nameReplyTo2')))->willReturnSelf(); |
75
|
|
|
$mail->expects($this->exactly(2)) |
76
|
|
|
->method('addPart') |
77
|
|
|
->withConsecutive( |
78
|
|
|
array($this->equalTo('message text'), $this->equalTo('text/plain')), |
79
|
|
|
array($this->equalTo('message html'), $this->equalTo('text/html')) |
80
|
|
|
) |
81
|
|
|
->willReturnSelf(); |
82
|
|
|
|
83
|
|
|
$this->mailer->expects($this->once())->method('createMessage')->will($this->returnValue($mail)); |
|
|
|
|
84
|
|
|
|
85
|
|
|
$method = new \ReflectionMethod($this->consumer, 'sendEmail'); |
86
|
|
|
$method->setAccessible(true); |
87
|
|
|
|
88
|
|
|
$method->invoke($this->consumer, $message); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.