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] = getenv($envName); |
30
|
|
|
putenv($envName.'=0'); |
31
|
|
|
} |
32
|
|
|
parent::setUp(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
protected function tearDown(): void |
36
|
|
|
{ |
37
|
|
|
foreach ($this->env as $envName => $envValue) { |
38
|
|
|
putenv($envName.'='.$envValue); |
39
|
|
|
} |
40
|
|
|
parent::tearDown(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testGetClientSecret() |
44
|
|
|
{ |
45
|
|
|
$envValue = 'UnitSecret'; |
46
|
|
|
putenv('CLIENT_SECRET='.$envValue); |
47
|
|
|
$this->assertSame($envValue,$this->config->getClientSecret()); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testGetClientSecretException() |
51
|
|
|
{ |
52
|
|
|
$this->expectException(RuntimeException::class); |
53
|
|
|
$this->config->getClientSecret(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testGetClientId() |
57
|
|
|
{ |
58
|
|
|
$envValue = 'UnitId'; |
59
|
|
|
putenv('CLIENT_ID='.$envValue); |
60
|
|
|
$this->assertSame($envValue,$this->config->getClientId()); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testGetClientIdException() |
64
|
|
|
{ |
65
|
|
|
$this->expectException(RuntimeException::class); |
66
|
|
|
$this->config->getClientId(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testGetRedirectUri() |
70
|
|
|
{ |
71
|
|
|
$envValue = 'UnitRedirectUri'; |
72
|
|
|
putenv('REDIRECT_URI='.$envValue); |
73
|
|
|
$this->assertSame($envValue,$this->config->getRedirectUri()); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function testGetRedirectUriException() |
77
|
|
|
{ |
78
|
|
|
$this->expectException(RuntimeException::class); |
79
|
|
|
$this->config->getRedirectUri(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function testGetSpotifyUsername() |
83
|
|
|
{ |
84
|
|
|
$envValue = 'UnitSpotifyUserName'; |
85
|
|
|
putenv('SPOTIFY_USERNAME='.$envValue); |
86
|
|
|
$this->assertSame($envValue,$this->config->getSpotifyUsername()); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function testGetSpotifyUsernameException() |
90
|
|
|
{ |
91
|
|
|
$this->expectException(RuntimeException::class); |
92
|
|
|
$this->config->getSpotifyUsername(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
} |