| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * @author Matteo Giachino <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | namespace GitElephant\Objects; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use \GitElephant\Objects\NodeObject; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use \GitElephant\TestCase; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 11 |  |  | class NodeObjectTest extends TestCase | 
            
                                                                        
                            
            
                                    
            
            
                | 12 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     public function setUp() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |         $this->initRepository(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |         $this->getRepository()->init(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |         $this->addFile('test-file'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |         $this->getRepository()->commit('first commit', true); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 19 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     public function testGetLastCommitFromTree() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         $tree = $this->getRepository()->getTree('master'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         $testFile = $tree[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         $this->assertInstanceOf('GitElephant\Objects\Commit', $testFile->getLastCommit()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         $this->assertEquals('first commit', $testFile->getLastCommit()->getMessage()); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 27 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     public function testGetLastCommitFromBranch() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         $this->getRepository()->createBranch('test'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $this->getRepository()->checkout('test'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $this->addFile('test-in-test-branch'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         $this->getRepository()->commit('test branch commit', true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         $tree = $this->getRepository()->getTree('test', 'test-in-test-branch'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $testFile = $tree->getBlob(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $this->assertInstanceOf('GitElephant\Objects\Commit', $testFile->getLastCommit()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $this->assertEquals('test branch commit', $testFile->getLastCommit()->getMessage()->getFullMessage()); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 39 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     public function testGetLastCommitFromTag() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $this->getRepository()->createTag('test-tag'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $tag = $this->getRepository()->getTag('test-tag'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $this->assertInstanceOf('GitElephant\Objects\Commit', $tag->getLastCommit()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $this->assertEquals('first commit', $tag->getLastCommit()->getMessage()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         $this->addFile('file2'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $this->getRepository()->commit('tag 2 commit', true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         $this->getRepository()->createTag('test-tag-2'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $tag = $this->getRepository()->getTag('test-tag-2'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $this->assertInstanceOf('GitElephant\Objects\Commit', $tag->getLastCommit()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         $this->assertEquals('tag 2 commit', $tag->getLastCommit()->getMessage()); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 53 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     public function testRevParse() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $master = $this->getRepository()->getBranch('master'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $revParse = $master->revParse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $this->assertEquals($master->getSha(), $revParse[0]); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 61 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |      * test repository getter and setter | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |      * @covers GitElephant\Objects\NodeObject::getRepository | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |      * @covers GitElephant\Objects\NodeObject::setRepository | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     public function testGetSetRepository() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $this->initRepository('object1', 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         $repo1 = $this->getRepository(1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $this->initRepository('object2', 2); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         $repo2 = $this->getRepository(2); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         $object = new NodeObject($repo1, 'permissions', 'type', 'sha', 'size', 'name', 'path'); // dummy params | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $this->assertSame($repo1, $object->getRepository()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         $object->setRepository($repo2); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         $this->assertSame($repo2, $object->getRepository()); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 81 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 82 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 83 |  |  |  |