| 
 | 1 | +<?php  | 
 | 2 | +/*  | 
 | 3 | + * This file is part of the GitCommandBundle package.  | 
 | 4 | + *  | 
 | 5 | + * (c) Paul Schweppe <paulschweppe@gmail.com>  | 
 | 6 | + *  | 
 | 7 | + * For the full copyright and license information, please view the LICENSE  | 
 | 8 | + * file that was distributed with this source code.  | 
 | 9 | + */  | 
 | 10 | + | 
 | 11 | +namespace VersionControl\GitCommandBundle\Tests\GitCommands\Command;  | 
 | 12 | + | 
 | 13 | +use VersionControl\GitCommandBundle\Tests\GitCommandTestCase;  | 
 | 14 | + | 
 | 15 | +/**  | 
 | 16 | + * GitFilesCommandTest.  | 
 | 17 | + * @author Paul Schweppe <paulschweppe@gmail.com>  | 
 | 18 | + */  | 
 | 19 | +class GitFilesCommandTest extends GitCommandTestCase  | 
 | 20 | +{  | 
 | 21 | +    /**  | 
 | 22 | +     * setUp, called on every method.  | 
 | 23 | +     */  | 
 | 24 | +    public function setUp()  | 
 | 25 | +    {  | 
 | 26 | +        $this->initGitCommandsLocal();  | 
 | 27 | +        $this->gitCommands->command('init')->initRepository();  | 
 | 28 | +        $this->addFile('test',null,'Test Of List Files');  | 
 | 29 | +        $this->addFolder('MoreFiles');  | 
 | 30 | +        $this->addFile('test2','MoreFiles','Test Of file in MoreFiles folder');  | 
 | 31 | +          | 
 | 32 | +        $this->gitCommands->command('commit')->stageAll();  | 
 | 33 | +        $this->gitCommands->command('commit')->commit('first commit', 'Paul Schweppe <paulschweppe@gmail.com>');  | 
 | 34 | +          | 
 | 35 | +        $this->addFile('test3',null,'This file is not commited');  | 
 | 36 | +          | 
 | 37 | +         | 
 | 38 | +    }  | 
 | 39 | + | 
 | 40 | +    /**  | 
 | 41 | +     * Test list files.  | 
 | 42 | +     */  | 
 | 43 | +    public function testListFiles()  | 
 | 44 | +    {  | 
 | 45 | +        $files = $this->gitCommands->command('files')->listFiles('');  | 
 | 46 | +          | 
 | 47 | +        $this->assertCount(3, $files,'File list count does not equal expected 3. Actual:'.count($files));  | 
 | 48 | +          | 
 | 49 | +        foreach($files as $file){  | 
 | 50 | +            $this->assertInstanceOf("\SplFileInfo", $file);  | 
 | 51 | +        }  | 
 | 52 | +          | 
 | 53 | +        $this->assertTrue($files[0]->isDir(), 'First file should be a directory');  | 
 | 54 | +        $this->assertTrue($files[1]->isFile(), 'Second file should be a file');  | 
 | 55 | +          | 
 | 56 | +        $this->assertInstanceOf("\VersionControl\GitCommandBundle\Entity\GitLog", $files[1]->getGitLog());  | 
 | 57 | +        $this->assertNull($files[2]->getGitLog(), 'Third file should not have a git log');  | 
 | 58 | +          | 
 | 59 | +        $errorMessage = '';  | 
 | 60 | +        try{  | 
 | 61 | +            $this->gitCommands->command('files')->listFiles('../');  | 
 | 62 | +        }catch(\VersionControl\GitCommandBundle\GitCommands\Exception\InvalidDirectoryException $e){  | 
 | 63 | +            $errorMessage = $e->getMessage();  | 
 | 64 | +        }  | 
 | 65 | +        $this->assertContains("Directory path is not valid", trim($errorMessage), 'Invalid Directory error');  | 
 | 66 | +    }  | 
 | 67 | +      | 
 | 68 | +    /**  | 
 | 69 | +     * Test Get File  | 
 | 70 | +     */  | 
 | 71 | +    public function testGetFile()  | 
 | 72 | +    {  | 
 | 73 | +        $file = $this->gitCommands->command('files')->getFile('MoreFiles/test2');  | 
 | 74 | +        $this->assertTrue($file->isFile(), '');  | 
 | 75 | +        $this->assertInstanceOf("\SplFileInfo", $file);  | 
 | 76 | +        $this->assertInstanceOf("\VersionControl\GitCommandBundle\Entity\GitLog", $file->getGitLog());  | 
 | 77 | +          | 
 | 78 | +          | 
 | 79 | +        $errorMessage = '';  | 
 | 80 | +        try{  | 
 | 81 | +            $fileNotExisting = $this->gitCommands->command('files')->getFile('MoreFiles/testDoesNotExist');  | 
 | 82 | +        }catch(\VersionControl\GitCommandBundle\GitCommands\Exception\InvalidDirectoryException $e){  | 
 | 83 | +            $errorMessage = $e->getMessage();  | 
 | 84 | +        }  | 
 | 85 | +          | 
 | 86 | +        $this->assertFalse($fileNotExisting->getRealPath(), '');  | 
 | 87 | +        //$this->assertContains("Directory path is not valid", trim($errorMessage), 'Invalid Directory error:'.$errorMessage);  | 
 | 88 | +    }  | 
 | 89 | +      | 
 | 90 | +      | 
 | 91 | + | 
 | 92 | + | 
 | 93 | +}  | 
0 commit comments