| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace AlexisLefebvre\Bundle\AsyncTweetsBundle\Command; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Symfony\Component\Console\Input\InputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Symfony\Component\Console\Input\InputArgument; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 8 |  |  | class StatusesHomeTimelineTestCommand extends StatusesHomeTimelineCommand | 
            
                                                                        
                            
            
                                    
            
            
                | 9 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 10 |  |  |     private $displayTable; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 11 |  |  |     private $table; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 12 |  |  |     private $progress; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  |      | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  |     /** @see https://dev.twitter.com/rest/reference/get/statuses/home_timeline */ | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |     private $parameters = array( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |         'count' => 200, | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |         'exclude_replies' => true | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |     ); | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 | 7 |  |     protected function configure() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 | 7 |  |         parent::configure(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 | 7 |  |         $this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 | 7 |  |             ->setName('statuses:hometimelinetest') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 | 7 |  |             ->setDescription('Fetch home timeline test') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 | 7 |  |             ->addArgument( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 | 7 |  |                 'test', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 | 7 |  |                 InputArgument::OPTIONAL, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |                 'Return data for tests' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 | 7 |  |             )     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         ; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 33 | 7 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |      | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |      * Read tweet(s) from a JSON file | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |      *  | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |      * @param string $filename | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |      * @return array | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 | 3 |  |     protected function getTestContent($filename) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         /** @see https://insight.sensiolabs.com/what-we-analyse/symfony.dependency_injection.use_dir_file_constant */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 | 3 |  |         return(json_decode(file_get_contents( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 3 |  |             $this->container->get('kernel')->locateResource( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |                 '@AsyncTweetsBundle/Tests/Command/data/'.$filename | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 | 3 |  |             ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 | 3 |  |         ))); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 49 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |      | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |      * @param InputInterface $input | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 | 7 |  |     protected function getContent(InputInterface $input) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 | 7 |  |         switch($input->getArgument('test')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 | 7 |  |             case 'json': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 | 2 |  |                 return($this->getTestContent( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 | 2 |  |                     'tweets_32_bits.json')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 | 5 |  |             case 'json_with_retweet': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 | 1 |  |                 return($this->getTestContent( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 | 1 |  |                     'tweet_with_retweet.json')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 4 |  |             case 'not_array': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |                 // Return null instead of JSON | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 1 |  |                 return(null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 | 3 |  |             case 'empty_array': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |                 // Return an empty array instead of JSON | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 | 2 |  |                 return(array()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 1 |  |             default: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |                 // Normal behaviour | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 1 |  |                 return(parent::getContent($input));  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 | 1 |  |         } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 73 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 74 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 75 |  |  |  |