|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* (c) Christian Gripp <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Core23\LastFm\Tests\Service; |
|
11
|
|
|
|
|
12
|
|
|
use Core23\LastFm\Client\ApiClientInterface; |
|
13
|
|
|
use Core23\LastFm\Service\AuthService; |
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
|
15
|
|
|
|
|
16
|
|
|
final class AuthServiceTest extends TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
private $client; |
|
19
|
|
|
|
|
20
|
|
|
protected function setUp(): void |
|
21
|
|
|
{ |
|
22
|
|
|
$this->client = $this->prophesize(ApiClientInterface::class); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function testCreateSession(): void |
|
26
|
|
|
{ |
|
27
|
|
|
$this->client->signedCall('auth.getSession', [ |
|
28
|
|
|
'token' => 'user-token', |
|
29
|
|
|
]) |
|
30
|
|
|
->willReturn([ |
|
31
|
|
|
'session' => [ |
|
32
|
|
|
'name' => 'FooBar', |
|
33
|
|
|
'key' => 'the-key', |
|
34
|
|
|
'subscriber' => 15, |
|
35
|
|
|
], |
|
36
|
|
|
]) |
|
37
|
|
|
; |
|
38
|
|
|
|
|
39
|
|
|
$service = new AuthService($this->client->reveal()); |
|
40
|
|
|
|
|
41
|
|
|
$result = $service->createSession('user-token'); |
|
42
|
|
|
|
|
43
|
|
|
static::assertNotNull($result); |
|
44
|
|
|
static::assertSame('FooBar', $result->getName()); |
|
45
|
|
|
static::assertSame('the-key', $result->getKey()); |
|
46
|
|
|
static::assertSame(15, $result->getSubscriber()); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testCreateToken(): void |
|
50
|
|
|
{ |
|
51
|
|
|
$this->client->signedCall('auth.getToken') |
|
52
|
|
|
->willReturn([ |
|
53
|
|
|
'token' => 'The Token', |
|
54
|
|
|
]) |
|
55
|
|
|
; |
|
56
|
|
|
|
|
57
|
|
|
$service = new AuthService($this->client->reveal()); |
|
58
|
|
|
static::assertSame('The Token', $service->createToken()); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function testGetAuthUrl(): void |
|
62
|
|
|
{ |
|
63
|
|
|
$this->client->getApiKey() |
|
64
|
|
|
->willReturn('api-key') |
|
65
|
|
|
; |
|
66
|
|
|
|
|
67
|
|
|
$service = new AuthService($this->client->reveal()); |
|
68
|
|
|
|
|
69
|
|
|
static::assertSame('http://www.last.fm/api/auth/?api_key=api-key&cb=https://example.org', $service->getAuthUrl('https://example.org')); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|