SessionTest::testGetAuthorizeUrl()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 11
c 2
b 0
f 0
dl 0
loc 17
rs 9.9
cc 1
nc 1
nop 0
1
<?php declare(strict_types=1);
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
class SessionTest extends TestCase
10
{
11
    /**
12
     * @var Session
13
     */
14
    private $session;
15
16
    protected function setUp() : void
17
    {
18
        parent::setUp();
19
20
        $this->session = new Session(
21
            new Config()
22
        );
23
    }
24
25
    public function testGetAuthorizeUrl()
26
    {
27
        $redirectUrl = $this->session->getAuthorizeUrl();
28
29
        $this->assertNotEmpty($redirectUrl, 'authorize url from spotify is empty');
30
        $parseRedirectUrl = parse_url($redirectUrl);
31
        $this->assertSame('accounts.spotify.com', $parseRedirectUrl['host']);
32
        $this->assertSame('/authorize', $parseRedirectUrl['path']);
33
34
        $this->assertNotEmpty($parseRedirectUrl['query']);
35
36
        $info = [];
37
        parse_str($parseRedirectUrl['query'], $info);
38
39
        $this->assertSame('code', $info['response_type']);
40
        $this->assertSame($_ENV['REDIRECT_URI'], $info['redirect_uri']);
41
        $this->assertTrue(isset($info['client_id']));
42
    }
43
44
    public function testRefreshAccessToken()
45
    {
46
        $this->assertTrue($this->session->refreshAccessToken($_ENV['REFRESH_TOKEN']));
47
        $this->assertNotEmpty($this->session->getAccessToken());
48
    }
49
50
}
51