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
|
|
|
]; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var Config |
21
|
|
|
*/ |
22
|
|
|
private $config; |
23
|
|
|
|
24
|
|
|
protected function setUp(): void |
25
|
|
|
{ |
26
|
|
|
$this->config = new Config(); |
27
|
|
|
foreach ($this->env as $envName => $envValue) { |
28
|
|
|
$this->env[$envName] = getenv($envName); |
29
|
|
|
putenv($envName.'=0'); |
30
|
|
|
} |
31
|
|
|
parent::setUp(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
protected function tearDown(): void |
35
|
|
|
{ |
36
|
|
|
foreach ($this->env as $envName => $envValue) { |
37
|
|
|
putenv($envName.'='.$envValue); |
38
|
|
|
} |
39
|
|
|
parent::tearDown(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testGetClientSecret() |
43
|
|
|
{ |
44
|
|
|
$envValue = 'UnitSecret'; |
45
|
|
|
putenv('CLIENT_SECRET='.$envValue); |
46
|
|
|
$this->assertSame($envValue,$this->config->getClientSecret()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testGetClientSecretException() |
50
|
|
|
{ |
51
|
|
|
$this->expectException(RuntimeException::class); |
52
|
|
|
$this->config->getClientSecret(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testGetClientId() |
56
|
|
|
{ |
57
|
|
|
$envValue = 'UnitId'; |
58
|
|
|
putenv('CLIENT_ID='.$envValue); |
59
|
|
|
$this->assertSame($envValue,$this->config->getClientId()); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testGetClientIdException() |
63
|
|
|
{ |
64
|
|
|
$this->expectException(RuntimeException::class); |
65
|
|
|
$this->config->getClientId(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testGetRedirectUri() |
69
|
|
|
{ |
70
|
|
|
$envValue = 'UnitRedirectUri'; |
71
|
|
|
putenv('REDIRECT_URI='.$envValue); |
72
|
|
|
$this->assertSame($envValue,$this->config->getRedirectUri()); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testGetRedirectUriException() |
76
|
|
|
{ |
77
|
|
|
$this->expectException(RuntimeException::class); |
78
|
|
|
$this->config->getRedirectUri(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
} |