| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Fmaj\LaposteDatanovaBundle\Tests\Model; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Fmaj\LaposteDatanovaBundle\Service\Downloader; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | class DownloaderTest extends \PHPUnit_Framework_TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |      * Simple find download test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     public function testFindDownload() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |         $dataset = 'laposte_hexasmal'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |         $format = 'json'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |         $filter = '34000'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |         $path = uniqid(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |         $client = $this->getClientMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |         $finder = $this->getFinderMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         $finder->expects($this->once()) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |             ->method('findDataset') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |             ->with($dataset, $format, $filter) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |             ->willReturn($path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         $downloader = new Downloader($client, $finder); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         $result = $downloader->findDownload($dataset, $format, $filter); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         $this->assertEquals($path, $result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * @return \PHPUnit_Framework_MockObject_MockObject|\Fmaj\LaposteDatanovaBundle\Client\ClientInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     private function getClientMock() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         return $this->getMockBuilder('Fmaj\LaposteDatanovaBundle\Client\ClientInterface') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             ->disableOriginalConstructor() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             ->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * @return \PHPUnit_Framework_MockObject_MockObject|\Fmaj\LaposteDatanovaBundle\Service\Finder | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 41 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |     private function getFinderMock() | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |         return $this->getMockBuilder('Fmaj\LaposteDatanovaBundle\Service\Finder') | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |             ->disableOriginalConstructor() | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |             ->getMock(); | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      * Simple test of download method | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     public function testDownload() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $dataset = 'laposte_hexasmal'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $format = 'json'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $filter = '34000'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $updateExisting = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         $content = uniqid(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $path = uniqid(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $client = $this->getClientMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         $client->expects($this->once()) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             ->method('setTimeout') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |             ->with(0); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $client->expects($this->once()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |             ->method('get') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |             ->with('download', array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |                 'dataset' => $dataset, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |                 'format' => $format, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |                 'q' => $filter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |             )) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |             ->willReturn($content) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         $finder = $this->getFinderMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $finder->expects($this->once()) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |             ->method('save') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |             ->with($dataset, $content, $format, $filter, $updateExisting) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |             ->willReturn($path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $finder->expects($this->once()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |             ->method('getContent') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |             ->with($path) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |             ->willReturn($content); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         $downloader = new Downloader($client, $finder); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         $result = $downloader->download($dataset, $format, $filter, $updateExisting); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         $this->assertEquals($content, $result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 86 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 87 |  |  |  | 
            
                        
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: