| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace BringYourOwnIdeas\UpdateChecker\Tests\Tasks; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use BringYourOwnIdeas\Maintenance\Tasks\UpdatePackageInfo; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use BringYourOwnIdeas\UpdateChecker\UpdateChecker; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use CheckComposerUpdatesTask; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Composer\Package\PackageInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Config; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use PHPUnit_Framework_TestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use SapphireTest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @mixin PHPUnit_Framework_TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | class CheckComposerUpdatesTaskTest extends SapphireTest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      * @var CheckComposerUpdatesTask | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     protected $task; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      * @var string[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     protected $allowedTypes; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     public function setUp() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         parent::setUp(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $this->task = CheckComposerUpdatesTask::create(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         $updateCheckerMock = $this->getMockBuilder(UpdateChecker::class)->setMethods(['checkForUpdates'])->getMock(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         $this->task->setUpdateChecker($updateCheckerMock); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $this->allowedTypes = ['silverstripe-module', 'silverstripe-vendormodule', 'silverstripe-theme']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         Config::inst()->update(UpdatePackageInfo::class, 'allowed_types', $this->allowedTypes); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     public function testRunPassesPackagesToUpdateChecker() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $this->task->getUpdateChecker()->expects($this->atLeastOnce()) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |             ->method('checkForUpdates') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |             ->with($this->isInstanceOf(PackageInterface::class), $this->isType('string')); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         $output = $this->runTask(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $this->assertContains('The task finished running', $output); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     public function testOnlyAllowedPackageTypesAreProcessed() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $this->task->getUpdateChecker()->expects($this->atLeastOnce()) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             ->method('checkForUpdates') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             ->with($this->callback(function ($argument) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |                 return in_array($argument->getType(), $this->allowedTypes); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             })); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $this->runTask(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * Runs the task and buffers the output (tasks output directly) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      * @return string Task output | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 66 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 67 |  |  |     protected function runTask() | 
            
                                                        
            
                                    
            
            
                | 68 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 69 |  |  |         ob_start(); | 
            
                                                        
            
                                    
            
            
                | 70 |  |  |         $this->task->run(null); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 71 |  |  |         return ob_get_clean(); | 
            
                                                        
            
                                    
            
            
                | 72 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 73 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 74 |  |  |  | 
            
                        
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.