| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This is part of the webuni/composer-yaml-plugin package. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * (c) Martin Hasoň <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * (c) Webuni s.r.o. <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * For the full copyright and license information, please view the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | namespace Webuni\ComposerYamlPlugin\Tests; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Composer\Composer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Composer\Console\Application; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Composer\IO\BufferIO; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Composer\Plugin\PluginManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Symfony\Component\Console\Input\ArrayInput; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use Symfony\Component\Console\Output\BufferedOutput; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use Webuni\ComposerYamlPlugin\Plugin; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  | final class PluginTest extends \PHPUnit_Framework_TestCase | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |     private $plugin; | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     protected function setUp() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         $this->plugin = new Plugin(); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 30 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     public function testAddNewCommand() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         /* @var $pm PluginManager|\PHPUnit_Framework_MockObject_MockObject */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         $pm = $this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             ->getMockBuilder(PluginManager::class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |             ->setMethods(['getPlugins']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             ->disableOriginalConstructor() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             ->getMock() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $pm | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |             ->expects($this->any()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |             ->method('getPlugins') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |             ->willReturn([$this->plugin]) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $composer = $this->getMockBuilder(Composer::class)->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         $composer | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             ->expects($this->any()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             ->method('getPluginManager') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |             ->willReturn($pm) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $this->plugin->activate($composer, new BufferIO()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         /* @var $app Application|\PHPUnit_Framework_MockObject_MockObject */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         $app = $this->getMockBuilder(Application::class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             ->setMethods(['getComposer']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             ->getMock() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $app | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |             ->expects($this->any()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |             ->method('getComposer') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |             ->willReturn($composer) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         $output = new BufferedOutput(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $app->doRun(new ArrayInput(['-d' => sys_get_temp_dir()]), $output); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         $this->assertRegExp('/yaml-convert +Converts a composer\.yml to json or vice-versa/', $output->fetch()); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 73 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 74 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 75 |  |  |  | 
            
                        
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: