ConfigTest   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 12
eloc 36
c 4
b 1
f 0
dl 0
loc 83
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetClientId() 0 5 1
A testGetSpotifyUsernameException() 0 4 1
A testGetRedirectUri() 0 5 1
A testGetSpotifyUsername() 0 5 1
A testGetClientSecretException() 0 4 1
A testGetClientSecret() 0 5 1
A setUp() 0 9 2
A testGetRedirectUriException() 0 4 1
A tearDown() 0 6 2
A testGetClientIdException() 0 4 1
1
<?php declare(strict_types=1);
2
3
4
namespace SpotifyApiConnectTest\Unit\Domain\Model;
5
6
7
use PHPUnit\Framework\TestCase;
8
use RuntimeException;
9
use SpotifyApiConnect\Domain\Model\Config;
10
11
class ConfigTest extends TestCase
12
{
13
    private $env = [
14
        'CLIENT_ID' => null,
15
        'CLIENT_SECRET' => null,
16
        'REDIRECT_URI' => null,
17
        'SPOTIFY_USERNAME' => null,
18
    ];
19
20
    /**
21
     * @var Config
22
     */
23
    private $config;
24
25
    protected function setUp(): void
26
    {
27
        $this->config = new Config();
28
        foreach ($this->env as $envName => $envValue) {
29
            $this->env[$envName] = $_ENV[$envName];
30
            $_ENV[$envName] = null;
31
            putenv($envName.'=0');
32
        }
33
        parent::setUp();
34
    }
35
36
    protected function tearDown(): void
37
    {
38
        foreach ($this->env as $envName => $envValue) {
39
            $_ENV[$envName] = $envValue;
40
        }
41
        parent::tearDown();
42
    }
43
44
    public function testGetClientSecret()
45
    {
46
        $envValue = 'UnitSecret';
47
        $_ENV['CLIENT_SECRET'] = $envValue;
48
        $this->assertSame($envValue,$this->config->getClientSecret());
49
    }
50
51
    public function testGetClientSecretException()
52
    {
53
        $this->expectException(RuntimeException::class);
54
        $this->config->getClientSecret();
55
    }
56
57
    public function testGetClientId()
58
    {
59
        $envValue = 'UnitId';
60
        $_ENV['CLIENT_ID'] = $envValue;
61
        $this->assertSame($envValue,$this->config->getClientId());
62
    }
63
64
    public function testGetClientIdException()
65
    {
66
        $this->expectException(RuntimeException::class);
67
        $this->config->getClientId();
68
    }
69
70
    public function testGetRedirectUri()
71
    {
72
        $envValue = 'UnitRedirectUri';
73
        $_ENV['REDIRECT_URI'] = $envValue;
74
        $this->assertSame($envValue,$this->config->getRedirectUri());
75
    }
76
77
    public function testGetRedirectUriException()
78
    {
79
        $this->expectException(RuntimeException::class);
80
        $this->config->getRedirectUri();
81
    }
82
83
    public function testGetSpotifyUsername()
84
    {
85
        $envValue = 'UnitSpotifyUserName';
86
        $_ENV['SPOTIFY_USERNAME'] = $envValue;
87
        $this->assertSame($envValue,$this->config->getSpotifyUsername());
88
    }
89
90
    public function testGetSpotifyUsernameException()
91
    {
92
        $this->expectException(RuntimeException::class);
93
        $this->config->getSpotifyUsername();
94
    }
95
96
}