Completed
Push — master ( a40ed3...30c58f )
by butschster
23s queued 19s
created

ConfigTest::testDefaultConfigWithQueue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 10
rs 10
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());
0 ignored issues
show
Deprecated Code introduced by
The function Spiral\SendIt\Config\Mai...fig::getQueuePipeline() has been deprecated: since v2.9. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

41
        $this->assertSame('emails', /** @scrutinizer ignore-deprecated */ $cfg->getQueuePipeline());

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.

Loading history...
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());
0 ignored issues
show
Deprecated Code introduced by
The function Spiral\SendIt\Config\Mai...fig::getQueuePipeline() has been deprecated: since v2.9. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

71
        $this->assertSame('emails', /** @scrutinizer ignore-deprecated */ $config->getQueuePipeline());

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.

Loading history...
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());
0 ignored issues
show
Deprecated Code introduced by
The function Spiral\SendIt\Config\Mai...fig::getQueuePipeline() has been deprecated: since v2.9. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

82
        $this->assertNull(/** @scrutinizer ignore-deprecated */ $config->getQueuePipeline());

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.

Loading history...
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());
0 ignored issues
show
Deprecated Code introduced by
The function Spiral\SendIt\Config\Mai...fig::getQueuePipeline() has been deprecated: since v2.9. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

94
        $this->assertSame('emails', /** @scrutinizer ignore-deprecated */ $config->getQueuePipeline());

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.

Loading history...
95
    }
96
97
    public function testGetsQueueConnectionWithoutKey(): void
98
    {
99
        $cfg = new MailerConfig();
100
        $this->assertNull($cfg->getQueueConnection());
101
    }
102
}
103