Passed
Push — master ( f6cdcb...e2cbe1 )
by Chema
03:23
created

StockTickerConfigTest::testTemplateDir()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chemaclass\StockTickerTests\Unit;
6
7
use Chemaclass\StockTicker\StockTickerConfig;
8
use Generator;
9
use PHPUnit\Framework\TestCase;
10
11
final class StockTickerConfigTest extends TestCase
12
{
13
    private const EXAMPLE_TEMPLATE_DIR = 'example template dir';
14
15
    public function testTemplateDir(): void
16
    {
17
        $config = new StockTickerConfig(self::EXAMPLE_TEMPLATE_DIR, []);
18
19
        self::assertSame(self::EXAMPLE_TEMPLATE_DIR, $config->getTemplatesDir());
20
    }
21
22
    public function testEmailChannelConfig(): void
23
    {
24
        $env = [
25
            'TO_ADDRESS' => 'TO_ADDRESS',
26
            'MAILER_USERNAME' => 'MAILER_USERNAME',
27
            'MAILER_PASSWORD' => 'MAILER_PASSWORD',
28
        ];
29
30
        $config = new StockTickerConfig(self::EXAMPLE_TEMPLATE_DIR, $env);
31
32
        self::assertSame($env['TO_ADDRESS'], $config->getToAddress());
33
        self::assertSame($env['MAILER_USERNAME'], $config->getMailerUsername());
34
        self::assertSame($env['MAILER_PASSWORD'], $config->getMailerPassword());
35
    }
36
37
    public function testSlackChannelConfig(): void
38
    {
39
        $env = [
40
            'SLACK_DESTINY_CHANNEL_ID' => 'SLACK_DESTINY_CHANNEL_ID',
41
            'SLACK_BOT_USER_OAUTH_ACCESS_TOKEN' => 'SLACK_BOT_USER_OAUTH_ACCESS_TOKEN',
42
        ];
43
44
        $config = new StockTickerConfig(self::EXAMPLE_TEMPLATE_DIR, $env);
45
46
        self::assertSame($env['SLACK_DESTINY_CHANNEL_ID'], $config->getSlackDestinyChannelId());
47
        self::assertSame($env['SLACK_BOT_USER_OAUTH_ACCESS_TOKEN'], $config->getSlackBotUserOauthAccessToken());
48
    }
49
50
    /**
51
     * @dataProvider providerDebugConfig
52
     */
53
    public function testDebugConfig(string $debugParam, bool $expected): void
54
    {
55
        $config = new StockTickerConfig(self::EXAMPLE_TEMPLATE_DIR, [
56
            'DEBUG' => $debugParam,
57
        ]);
58
59
        self::assertEquals($expected, $config->isDebug());
60
    }
61
62
    public function providerDebugConfig(): Generator
63
    {
64
        yield [
65
            'debugParam' => 'true',
66
            'expected' => true,
67
        ];
68
69
        yield [
70
            'debugParam' => '1',
71
            'expected' => true,
72
        ];
73
74
        yield [
75
            'debugParam' => 'yes',
76
            'expected' => true,
77
        ];
78
79
        yield [
80
            'debugParam' => 'false',
81
            'expected' => false,
82
        ];
83
84
        yield [
85
            'debugParam' => '0',
86
            'expected' => false,
87
        ];
88
89
        yield [
90
            'debugParam' => 'no',
91
            'expected' => false,
92
        ];
93
    }
94
}
95