|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Spiral\Tests\SendIt; |
|
6
|
|
|
|
|
7
|
|
|
use Mockery as m; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
use Spiral\Mailer\Message; |
|
10
|
|
|
use Spiral\Queue\Options; |
|
11
|
|
|
use Spiral\Queue\QueueInterface; |
|
12
|
|
|
use Spiral\SendIt\Config\MailerConfig; |
|
13
|
|
|
use Spiral\SendIt\MailQueue; |
|
14
|
|
|
use Spiral\SendIt\MessageSerializer; |
|
15
|
|
|
|
|
16
|
|
|
class QueueTest extends TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
/** @var m\LegacyMockInterface|m\MockInterface|QueueInterface */ |
|
19
|
|
|
private $queue; |
|
20
|
|
|
/** @var MailQueue */ |
|
21
|
|
|
private $mailer; |
|
22
|
|
|
|
|
23
|
|
|
protected function setUp(): void |
|
24
|
|
|
{ |
|
25
|
|
|
parent::setUp(); |
|
26
|
|
|
|
|
27
|
|
|
$this->queue = m::mock(QueueInterface::class); |
|
28
|
|
|
|
|
29
|
|
|
$this->mailer = new MailQueue( |
|
30
|
|
|
new MailerConfig([ |
|
31
|
|
|
'pipeline' => 'mailer', |
|
32
|
|
|
]), |
|
33
|
|
|
$this->queue |
|
34
|
|
|
); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function testQueue(): void |
|
38
|
|
|
{ |
|
39
|
|
|
$mail = new Message('test', ['[email protected]'], ['key' => 'value']); |
|
40
|
|
|
$mail->setFrom('[email protected]'); |
|
41
|
|
|
$mail->setReplyTo('[email protected]'); |
|
42
|
|
|
$mail->setCC('[email protected]'); |
|
43
|
|
|
$mail->setBCC('[email protected]'); |
|
44
|
|
|
|
|
45
|
|
|
$this->queue->expects('push')->withArgs( |
|
|
|
|
|
|
46
|
|
|
function ($job, $data, Options $options) use ($mail) { |
|
47
|
|
|
$this->assertSame(MailQueue::JOB_NAME, $job); |
|
48
|
|
|
$this->assertSame($data, MessageSerializer::pack($mail)); |
|
49
|
|
|
$this->assertSame('mailer', $options->getQueue()); |
|
50
|
|
|
$this->assertNull($options->getDelay()); |
|
51
|
|
|
|
|
52
|
|
|
return true; |
|
53
|
|
|
} |
|
54
|
|
|
); |
|
55
|
|
|
|
|
56
|
|
|
$this->mailer->send($mail); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function testQueueWithDelay(): void |
|
60
|
|
|
{ |
|
61
|
|
|
$mail1 = new Message('test', ['[email protected]'], ['key' => 'value']); |
|
62
|
|
|
$mail1->setDelay(new \DateInterval('PT30S')); |
|
63
|
|
|
|
|
64
|
|
|
$mail2 = new Message('test', ['[email protected]'], ['key' => 'value']); |
|
65
|
|
|
$mail2->setDelay((new \DateTimeImmutable('+100 second'))); |
|
66
|
|
|
|
|
67
|
|
|
$mail3 = new Message('test', ['[email protected]'], ['key' => 'value']); |
|
68
|
|
|
$mail3->setDelay(200); |
|
69
|
|
|
|
|
70
|
|
|
$this->queue->expects('push')->once()->withArgs( |
|
71
|
|
|
function ($job, $data, Options $options) { |
|
72
|
|
|
$this->assertSame(30, $options->getDelay()); |
|
73
|
|
|
return true; |
|
74
|
|
|
} |
|
75
|
|
|
); |
|
76
|
|
|
|
|
77
|
|
|
$this->queue->expects('push')->once()->withArgs( |
|
78
|
|
|
function ($job, $data, Options $options) { |
|
79
|
|
|
$this->assertSame(100, $options->getDelay()); |
|
80
|
|
|
return true; |
|
81
|
|
|
} |
|
82
|
|
|
); |
|
83
|
|
|
|
|
84
|
|
|
$this->queue->expects('push')->once()->withArgs( |
|
85
|
|
|
function ($job, $data, Options $options) { |
|
86
|
|
|
$this->assertSame(200, $options->getDelay()); |
|
87
|
|
|
return true; |
|
88
|
|
|
} |
|
89
|
|
|
); |
|
90
|
|
|
|
|
91
|
|
|
$this->mailer->send($mail1, $mail2, $mail3); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
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.