Skip to content

Commit 3de1da2

Browse files
bobfloatsroot
authored andcommitted
Added Git Files Command Tests
1 parent 0ed38e5 commit 3de1da2

File tree

3 files changed

+95
-1
lines changed

3 files changed

+95
-1
lines changed

src/VersionControl/GitCommandBundle/GitCommands/Command/GitFilesCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ protected function getFileInfo($path)
8989

9090
$fileInfo = $newFileInfo;
9191
}
92+
9293

9394
return $fileInfo;
9495
}

src/VersionControl/GitCommandBundle/GitCommands/Exception/InvalidDirectoryException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace VersionControl\GitCommandBundle\GitCommands\Exception;
1313

1414
/**
15-
* InvalidArgumentException.
15+
* InvalidDirectoryException.
1616
*
1717
* @author Paul Schweppe <paulschweppe@gmail.com>
1818
*/
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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

Comments
 (0)