| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace BringYourOwnIdeas\UpdateChecker\Tests; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use BringYourOwnIdeas\UpdateChecker\UpdateChecker; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Composer\Composer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Composer\Package\RootPackage; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Injector; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Package; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use PHPUnit_Framework_TestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use SapphireTest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @mixin PHPUnit_Framework_TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | class UpdateCheckerTest extends SapphireTest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     protected $usesDatabase = true; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 20 |  |  |     public function testAvailableUpdatesAreWrittenToPackageModel() | 
            
                                                        
            
                                    
            
            
                | 21 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 22 |  |  |         // Mock Composer | 
            
                                                        
            
                                    
            
            
                | 23 |  |  |         $composerMock = $this->getMock(Composer::class); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 24 |  |  |         Injector::inst()->registerService($composerMock, Composer::class); | 
            
                                                        
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 26 |  |  |         // Create mock package | 
            
                                                        
            
                                    
            
            
                | 27 |  |  |         $packageMock = $this->getMockBuilder(RootPackage::class) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 28 |  |  |             ->disableOriginalConstructor() | 
            
                                                        
            
                                    
            
            
                | 29 |  |  |             ->setMethods(['getName', 'getPrettyVersion', 'getSourceReference']) | 
            
                                                        
            
                                    
            
            
                | 30 |  |  |             ->getMock(); | 
            
                                                        
            
                                    
            
            
                | 31 |  |  |         $packageMock->expects($this->once()) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 32 |  |  |             ->method('getName') | 
            
                                                        
            
                                    
            
            
                | 33 |  |  |             ->will($this->returnValue('foo/module')); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 34 |  |  |         $packageMock->expects($this->exactly(3)) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 35 |  |  |             ->method('getPrettyVersion') | 
            
                                                        
            
                                    
            
            
                | 36 |  |  |             ->will($this->onConsecutiveCalls('1.2.0', '1.2.3', '2.3.4')); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 37 |  |  |         $packageMock->expects($this->exactly(3)) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 38 |  |  |             ->method('getSourceReference') | 
            
                                                        
            
                                    
            
            
                | 39 |  |  |             ->will($this->onConsecutiveCalls('1a2s3d4f', '8s7d6f5g', '9g8f7d6s')); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 41 |  |  |         // Partially mock the update checker | 
            
                                                        
            
                                    
            
            
                | 42 |  |  |         $checker = $this->getMockBuilder(UpdateChecker::class)->setMethods(['findLatestPackage'])->getMock(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 43 |  |  |         $checker->expects($this->exactly(2)) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 44 |  |  |             ->method('findLatestPackage') | 
            
                                                        
            
                                    
            
            
                | 45 |  |  |             ->will($this->returnValue($packageMock)); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 47 |  |  |         // Run the checker | 
            
                                                        
            
                                    
            
            
                | 48 |  |  |         $checker->checkForUpdates($packageMock, '~1.2'); | 
            
                                                        
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 50 |  |  |         // Check the database for results | 
            
                                                        
            
                                    
            
            
                | 51 |  |  |         $module = Package::get()->filter(['Name' => 'foo/module'])->first(); | 
            
                                                        
            
                                    
            
            
                | 52 |  |  |         $this->assertNotEmpty($module); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 54 |  |  |         $this->assertSame('1a2s3d4f', $module->VersionHash, 'The current hash is recorded'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 55 |  |  |         $this->assertSame('8s7d6f5g', $module->AvailableHash, 'The next available hash is recorded'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 56 |  |  |         $this->assertSame('9g8f7d6s', $module->LatestHash, 'The latest available hash is recorded'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 58 |  |  |         $this->assertSame('1.2.0', $module->Version, 'The current version is recorded'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 59 |  |  |         $this->assertSame('1.2.3', $module->AvailableVersion, 'The available version is recorded'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 60 |  |  |         $this->assertSame('2.3.4', $module->LatestVersion, 'The latest available version is recorded'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 62 |  |  |         $this->assertSame('~1.2', $module->VersionConstraint, 'The installation constraint is recorded'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 63 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 64 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 65 |  |  |  | 
            
                        
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.