|
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\Builder; |
|
11
|
|
|
|
|
12
|
|
|
use Core23\LastFm\Builder\TrackBuilder; |
|
13
|
|
|
use DateTime; |
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
|
15
|
|
|
|
|
16
|
|
|
final class TrackBuilderTest extends TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
public function testCreate(): void |
|
19
|
|
|
{ |
|
20
|
|
|
$now = new DateTime(); |
|
21
|
|
|
|
|
22
|
|
|
$builder = TrackBuilder::create('Slipknot', 'Before I Forget', $now); |
|
23
|
|
|
|
|
24
|
|
|
$expected = [ |
|
25
|
|
|
'artist' => 'Slipknot', |
|
26
|
|
|
'track' => 'Before I Forget', |
|
27
|
|
|
'timestamp' => $now->getTimestamp(), |
|
28
|
|
|
]; |
|
29
|
|
|
static::assertSame($expected, $builder->getData()); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testWithAlbum(): void |
|
33
|
|
|
{ |
|
34
|
|
|
$now = new DateTime(); |
|
35
|
|
|
|
|
36
|
|
|
$builder = TrackBuilder::create('Slipknot', 'Before I Forget', $now) |
|
37
|
|
|
->withAlbum('IOWA') |
|
38
|
|
|
; |
|
39
|
|
|
|
|
40
|
|
|
$expected = [ |
|
41
|
|
|
'artist' => 'Slipknot', |
|
42
|
|
|
'track' => 'Before I Forget', |
|
43
|
|
|
'timestamp' => $now->getTimestamp(), |
|
44
|
|
|
'album' => 'IOWA', |
|
45
|
|
|
]; |
|
46
|
|
|
static::assertSame($expected, $builder->getData()); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testWithAlbumArtist(): void |
|
50
|
|
|
{ |
|
51
|
|
|
$now = new DateTime(); |
|
52
|
|
|
|
|
53
|
|
|
$builder = TrackBuilder::create('Slipknot', 'Before I Forget', $now) |
|
54
|
|
|
->withAlbumArtist('Slipknot') |
|
55
|
|
|
; |
|
56
|
|
|
|
|
57
|
|
|
$expected = [ |
|
58
|
|
|
'artist' => 'Slipknot', |
|
59
|
|
|
'track' => 'Before I Forget', |
|
60
|
|
|
'timestamp' => $now->getTimestamp(), |
|
61
|
|
|
'albumArtist' => 'Slipknot', |
|
62
|
|
|
]; |
|
63
|
|
|
static::assertSame($expected, $builder->getData()); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function testWithChosenByUser(): void |
|
67
|
|
|
{ |
|
68
|
|
|
$now = new DateTime(); |
|
69
|
|
|
|
|
70
|
|
|
$builder = TrackBuilder::create('Slipknot', 'Before I Forget', $now) |
|
71
|
|
|
->withChosenByUser(true) |
|
72
|
|
|
; |
|
73
|
|
|
|
|
74
|
|
|
$expected = [ |
|
75
|
|
|
'artist' => 'Slipknot', |
|
76
|
|
|
'track' => 'Before I Forget', |
|
77
|
|
|
'timestamp' => $now->getTimestamp(), |
|
78
|
|
|
'chosenByUser' => 1, |
|
79
|
|
|
]; |
|
80
|
|
|
static::assertSame($expected, $builder->getData()); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function testWithTrackNumber(): void |
|
84
|
|
|
{ |
|
85
|
|
|
$now = new DateTime(); |
|
86
|
|
|
|
|
87
|
|
|
$builder = TrackBuilder::create('Slipknot', 'Before I Forget', $now) |
|
88
|
|
|
->withTrackNumber(11) |
|
89
|
|
|
; |
|
90
|
|
|
|
|
91
|
|
|
$expected = [ |
|
92
|
|
|
'artist' => 'Slipknot', |
|
93
|
|
|
'track' => 'Before I Forget', |
|
94
|
|
|
'timestamp' => $now->getTimestamp(), |
|
95
|
|
|
'trackNumber' => 11, |
|
96
|
|
|
]; |
|
97
|
|
|
static::assertSame($expected, $builder->getData()); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function testWithStreamId(): void |
|
101
|
|
|
{ |
|
102
|
|
|
$now = new DateTime(); |
|
103
|
|
|
|
|
104
|
|
|
$builder = TrackBuilder::create('Slipknot', 'Before I Forget', $now) |
|
105
|
|
|
->withStreamId(11) |
|
106
|
|
|
; |
|
107
|
|
|
|
|
108
|
|
|
$expected = [ |
|
109
|
|
|
'artist' => 'Slipknot', |
|
110
|
|
|
'track' => 'Before I Forget', |
|
111
|
|
|
'timestamp' => $now->getTimestamp(), |
|
112
|
|
|
'streamId' => 11, |
|
113
|
|
|
]; |
|
114
|
|
|
static::assertSame($expected, $builder->getData()); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
public function testWithContext(): void |
|
118
|
|
|
{ |
|
119
|
|
|
$now = new DateTime(); |
|
120
|
|
|
|
|
121
|
|
|
$builder = TrackBuilder::create('Slipknot', 'Before I Forget', $now) |
|
122
|
|
|
->withContext('Client Version') |
|
123
|
|
|
; |
|
124
|
|
|
|
|
125
|
|
|
$expected = [ |
|
126
|
|
|
'artist' => 'Slipknot', |
|
127
|
|
|
'track' => 'Before I Forget', |
|
128
|
|
|
'timestamp' => $now->getTimestamp(), |
|
129
|
|
|
'context' => 'Client Version', |
|
130
|
|
|
]; |
|
131
|
|
|
static::assertSame($expected, $builder->getData()); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
public function testWithMbid(): void |
|
135
|
|
|
{ |
|
136
|
|
|
$now = new DateTime(); |
|
137
|
|
|
|
|
138
|
|
|
$builder = TrackBuilder::create('Slipknot', 'Before I Forget', $now) |
|
139
|
|
|
->withMbid('a466c2a2-6517-42fb-a160-1087c3bafd9f') |
|
140
|
|
|
; |
|
141
|
|
|
|
|
142
|
|
|
$expected = [ |
|
143
|
|
|
'artist' => 'Slipknot', |
|
144
|
|
|
'track' => 'Before I Forget', |
|
145
|
|
|
'timestamp' => $now->getTimestamp(), |
|
146
|
|
|
'mbid' => 'a466c2a2-6517-42fb-a160-1087c3bafd9f', |
|
147
|
|
|
]; |
|
148
|
|
|
static::assertSame($expected, $builder->getData()); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
public function testWithDuration(): void |
|
152
|
|
|
{ |
|
153
|
|
|
$now = new DateTime(); |
|
154
|
|
|
|
|
155
|
|
|
$builder = TrackBuilder::create('Slipknot', 'Before I Forget', $now) |
|
156
|
|
|
->withDuration(183) |
|
157
|
|
|
; |
|
158
|
|
|
|
|
159
|
|
|
$expected = [ |
|
160
|
|
|
'artist' => 'Slipknot', |
|
161
|
|
|
'track' => 'Before I Forget', |
|
162
|
|
|
'timestamp' => $now->getTimestamp(), |
|
163
|
|
|
'duration' => 183, |
|
164
|
|
|
]; |
|
165
|
|
|
static::assertSame($expected, $builder->getData()); |
|
166
|
|
|
} |
|
167
|
|
|
} |
|
168
|
|
|
|