|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Spiral Framework. |
|
5
|
|
|
* |
|
6
|
|
|
* @license MIT |
|
7
|
|
|
* @author Anton Titov (Wolfy-J) |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace Spiral\Tests\SendIt; |
|
13
|
|
|
|
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
|
15
|
|
|
use Spiral\Boot\Environment; |
|
16
|
|
|
use Spiral\SendIt\Config\MailerConfig; |
|
17
|
|
|
|
|
18
|
|
|
class ConfigTest extends TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
public function testConfig(): void |
|
21
|
|
|
{ |
|
22
|
|
|
$cfg = new MailerConfig([ |
|
23
|
|
|
'dsn' => 'mailer-dsn', |
|
24
|
|
|
'from' => '[email protected]', |
|
25
|
|
|
'queue' => 'emails', |
|
26
|
|
|
'queueConnection' => 'foo', |
|
27
|
|
|
]); |
|
28
|
|
|
|
|
29
|
|
|
$this->assertSame('mailer-dsn', $cfg->getDSN()); |
|
30
|
|
|
$this->assertSame('[email protected]', $cfg->getFromAddress()); |
|
31
|
|
|
$this->assertSame('emails', $cfg->getQueue()); |
|
32
|
|
|
$this->assertSame('foo', $cfg->getQueueConnection()); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function testWithDeprecatedPipeline(): void |
|
36
|
|
|
{ |
|
37
|
|
|
$cfg = new MailerConfig([ |
|
38
|
|
|
'pipeline' => 'emails', |
|
39
|
|
|
]); |
|
40
|
|
|
|
|
41
|
|
|
$this->assertSame('emails', $cfg->getQueuePipeline()); |
|
|
|
|
|
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function testDefaultConfig(): void |
|
45
|
|
|
{ |
|
46
|
|
|
$env = new Environment(); |
|
47
|
|
|
|
|
48
|
|
|
$config = new MailerConfig([ |
|
49
|
|
|
'dsn' => $env->get('MAILER_DSN', ''), |
|
50
|
|
|
'pipeline' => $env->get('MAILER_QUEUE', $env->get('MAILER_PIPELINE', 'local')), |
|
51
|
|
|
'queue' => $env->get('MAILER_QUEUE', 'local'), |
|
52
|
|
|
'from' => $env->get('MAILER_FROM', 'Spiral <[email protected]>'), |
|
53
|
|
|
'queueConnection' => $env->get('MAILER_QUEUE_CONNECTION'), |
|
54
|
|
|
]); |
|
55
|
|
|
|
|
56
|
|
|
$this->assertSame('', $config->getDSN()); |
|
57
|
|
|
$this->assertSame('Spiral <[email protected]>', $config->getFromAddress()); |
|
58
|
|
|
$this->assertSame('local', $config->getQueue()); |
|
59
|
|
|
$this->assertNull($config->getQueueConnection()); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function testDefaultConfigWithQueue(): void |
|
63
|
|
|
{ |
|
64
|
|
|
$env = new Environment(['MAILER_QUEUE' => 'emails']); |
|
65
|
|
|
|
|
66
|
|
|
$config = new MailerConfig([ |
|
67
|
|
|
'queue' => $env->get('MAILER_QUEUE', 'local'), |
|
68
|
|
|
]); |
|
69
|
|
|
|
|
70
|
|
|
$this->assertSame('emails', $config->getQueue()); |
|
71
|
|
|
$this->assertSame('emails', $config->getQueuePipeline()); |
|
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function testQueueWithNull(): void |
|
75
|
|
|
{ |
|
76
|
|
|
$config = new MailerConfig([ |
|
77
|
|
|
'pipeline' => null, |
|
78
|
|
|
'queue' => null, |
|
79
|
|
|
]); |
|
80
|
|
|
|
|
81
|
|
|
$this->assertNull($config->getQueue()); |
|
82
|
|
|
$this->assertNull($config->getQueuePipeline()); |
|
|
|
|
|
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function testDefaultConfigWithPippeline(): void |
|
86
|
|
|
{ |
|
87
|
|
|
$env = new Environment(['MAILER_PIPELINE' => 'emails']); |
|
88
|
|
|
|
|
89
|
|
|
$config = new MailerConfig([ |
|
90
|
|
|
'pipeline' => $env->get('MAILER_QUEUE', $env->get('MAILER_PIPELINE', 'local')), |
|
91
|
|
|
]); |
|
92
|
|
|
|
|
93
|
|
|
$this->assertSame('emails', $config->getQueue()); |
|
94
|
|
|
$this->assertSame('emails', $config->getQueuePipeline()); |
|
|
|
|
|
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function testGetsQueueConnectionWithoutKey(): void |
|
98
|
|
|
{ |
|
99
|
|
|
$cfg = new MailerConfig(); |
|
100
|
|
|
$this->assertNull($cfg->getQueueConnection()); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.