| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace N98\Magento\Command\Developer\Console; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Magento\Framework\App\State; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Magento\Framework\Filesystem\Directory\WriteInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use N98\Magento\Command\TestCase as BaseTestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use PHPUnit_Framework_MockObject_MockObject; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Psy\Context; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Symfony\Component\Console\Input\ArgvInput; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Symfony\Component\Console\Output\ConsoleOutput; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Symfony\Component\Console\Tester\CommandTester; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | abstract class TestCase extends BaseTestCase | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 15 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |     protected function setUp() | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |         if ($this->runsInProductionMode()) { | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |             $this->markTestSkipped('Developer command is not available in production mode'); | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |         parent::setUp(); | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     private function runsInProductionMode() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         $di = $this->getApplication()->getObjectManager(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         $input = new ArgvInput(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         $output = new ConsoleOutput(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         /* @var $mode \Magento\Deploy\Model\Mode */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $mode = $di->create( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |             'Magento\Deploy\Model\Mode', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |                 'input'  => $input, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |                 'output' => $output, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         return $mode->getMode() === State::MODE_PRODUCTION; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      * @param AbstractConsoleCommand $command | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      * @return CommandTester | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     public function createCommandTester(AbstractConsoleCommand $command) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $di = $this->getApplication()->getObjectManager(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         $command->setContext(new Context()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $command->setScopeVariable('di', $di); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $commandTester = new CommandTester($command); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         return $commandTester; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * @param string $reference | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * @return PHPUnit_Framework_MockObject_MockObject|WriteInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     protected function mockWriterFileCWriteFileAssertion($reference) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $path = sprintf(__DIR__ . '/_files/reference/%s.php', ucfirst($reference)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         $writerMock = $this->getMock(WriteInterface::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         $writerMock | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |             ->expects($this->once()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |             ->method('writeFile') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             ->with( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |                 $this->anything(), // param1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |                 $this->callback(function ($subject) use ($path) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |                     // apply cs-fixes as the code generator is a mess | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |                     $replacements = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |                         // empty class/interface | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |                         '~\{\n\n\n\}\n\n$~' => "{\n}\n", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |                         // fix end of file for class w content | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |                         '~    \}\n\n\n\}\n\n$~' => "    }\n}\n", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |                         // fix beginning of class | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |                         '~^(class .*)\n{\n\n~m' => "\\1\n{\n", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |                     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |                     $buffer = preg_replace(array_keys($replacements), $replacements, $subject); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |                     $expected = file_get_contents($path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |                     $this->assertEquals($expected, $buffer); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |                     return $buffer === $expected; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |                 }) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         return $writerMock; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 95 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 96 |  |  |  | 
            
                        
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: