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
|
|
|
} |