Completed
Push — master ( 379c63...bb81c5 )
by Rafal
22s
created

SessionTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 22
dl 0
loc 44
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testRefreshAccessToken() 0 4 1
A testGetAuthorizeUrl() 0 17 1
A setUp() 0 10 1
1
<?php
2
3
namespace SpotifyApiConnectTest\Integration\Application\SpotifyWebApiPhp;
4
5
use PHPUnit\Framework\TestCase;
6
use SpotifyApiConnect\Application\SpotifyWebApiPhp\Session;
7
use SpotifyApiConnect\Domain\Model\Config;
8
9
10
class SessionTest extends TestCase
11
{
12
    /**
13
     * @var Session
14
     */
15
    private $session;
16
17
    protected function setUp()
18
    {
19
        parent::setUp();
20
        $config = new Config(
21
            getenv('CLIENT_ID'),
22
            getenv('CLIENT_SECRET'),
23
            getenv('REDIRECT_URI')
24
        );
25
        $this->session = new Session(
26
            $config
27
        );
28
    }
29
30
31
    public function testGetAuthorizeUrl()
32
    {
33
        $redirectUrl = $this->session->getAuthorizeUrl();
34
35
        $this->assertNotEmpty($redirectUrl, 'authorize url from spotify is empty');
36
        $parseRedirectUrl = parse_url($redirectUrl);
37
        $this->assertSame('accounts.spotify.com', $parseRedirectUrl['host']);
38
        $this->assertSame('/authorize', $parseRedirectUrl['path']);
39
40
        $this->assertNotEmpty($parseRedirectUrl['query']);
41
42
        $info = [];
43
        parse_str($parseRedirectUrl['query'], $info);
44
45
        $this->assertSame('code', $info['response_type']);
46
        $this->assertSame('http://localhost/', $info['redirect_uri']);
47
        $this->assertTrue(isset($info['client_id']));
48
    }
49
50
    public function testRefreshAccessToken()
51
    {
52
        $this->assertTrue($this->session->refreshAccessToken(getenv('REFRESH_TOKEN')));
53
        $this->assertNotEmpty($this->session->getAccessToken());
54
    }
55
56
}
57