| 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\ScrobbeBuilder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Core23\LastFm\Builder\TrackBuilder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use DateTime; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use PHPUnit\Framework\TestCase; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  | final class ScrobbeBuilderTest extends TestCase | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     public function testCreate(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         $builder = ScrobbeBuilder::create(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         $expected = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         static::assertSame($expected, $builder->getQuery()); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 26 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     public function testCount(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         $builder = ScrobbeBuilder::create(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         static::assertSame(0, $builder->count()); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 33 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     public function testAddTrack(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $now       = new DateTime(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $yesterday = new DateTime('Yesterday'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $builder = ScrobbeBuilder::create() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |             ->addTrack(TrackBuilder::create('Slipknot', 'Before I Forget', $now)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |             ->addTrack(TrackBuilder::create('The Beatles', 'Yesterday', $yesterday)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $expected = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             'artist[0]'    => 'Slipknot', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             'track[0]'     => 'Before I Forget', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |             'timestamp[0]' => $now->getTimestamp(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             'artist[1]'    => 'The Beatles', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             'track[1]'     => 'Yesterday', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             'timestamp[1]' => $yesterday->getTimestamp(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         static::assertSame($expected, $builder->getQuery()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         static::assertSame(2, $builder->count()); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 55 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 56 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 57 |  |  |  |