Skip to content

Commit 080c7cb

Browse files
bobfloatsroot
authored andcommitted
Add more unit test
1 parent c3c3220 commit 080c7cb

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

src/VersionControl/GitCommandBundle/Tests/GitCommands/Command/GitFilesCommandTest.php

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -174,44 +174,55 @@ public function testIgnoreFile()
174174
$this->assertEquals('File path was not valid. Please check that the file exists.',$message);
175175
}
176176

177+
/**
178+
* @expectedException \VersionControl\GitCommandBundle\GitCommands\Exception\FileStatusException
179+
*/
180+
public function testUnTrackFileExceptionFromRepoNotCommitted()
181+
{
182+
// make your exception assertions
183+
//$this->expectException(\VersionControl\GitCommandBundle\GitCommands\Exception\FileStatusException::class);
184+
//$this->expectExceptionMessage('Please commit all files first');
185+
186+
$filesCommand = $this->gitCommands->command('files');
187+
$filesCommand->unTrackFile('test');
188+
189+
}
177190

178191
public function testUnTrackFile()
179192
{
180193
$filesCommand = $this->gitCommands->command('files');
181194

182-
//$this->assertTrue($filesCommand->isFileTracked('test'),'Test that test file is tracked');
195+
//Commit all files
196+
$this->gitCommands->command('commit')->stageAll();
197+
$this->gitCommands->command('commit')->commit('second commit', 'Paul Schweppe <paulschweppe@gmail.com>');
183198

184-
//Some files are not commits so an exception will be thrown
185-
$message = '';
186-
try{
187-
$filesCommand->unTrackFile('test');
188-
}catch(\VersionControl\GitCommandBundle\GitCommands\Exception\FileStatusException $e){
189-
$message = $e->getMessage();
190-
}
191-
$this->assertEquals('Please commit all files first',$message);
199+
//Untrack file should now work
200+
$response = $filesCommand->unTrackFile('test');
201+
$this->assertContains('Please commit to complete the removal',$response);
202+
203+
}
204+
205+
public function testFileNolongerTrackAfterUntrackFile()
206+
{
207+
$filesCommand = $this->gitCommands->command('files');
192208

193209
//Commit all files
194210
$this->gitCommands->command('commit')->stageAll();
195211
$this->gitCommands->command('commit')->commit('second commit', 'Paul Schweppe <paulschweppe@gmail.com>');
196212

197213
//Untrack file should now work
198-
$response2 = $filesCommand->unTrackFile('test');
199-
$this->assertContains('Please commit to complete the removal',$response2);
214+
$filesCommand->unTrackFile('test');
200215

201-
//Add test to .gitignore
202-
$this->updateFile('.gitignore',null,'test');
216+
//Add test to .gitignore. Must happen before commit
217+
$this->updateFile('.gitignore','test');
203218

204219
//Commit change to untracked file
205-
//$this->command->runCommand('git add .');
206-
//$this->gitCommands->command('commit')->stageAll();
207-
//$this->gitCommands->command('commit')->commit('Remove file from git index', 'Paul Schweppe <paulschweppe@gmail.com>');
220+
$this->gitCommands->command('commit')->stageAll();
221+
$this->gitCommands->command('commit')->commit('Remove file from git index', 'Paul Schweppe <paulschweppe@gmail.com>');
208222

209223
//Test that file is no longer tracked
210224
$this->assertFalse($filesCommand->isFileTracked('test'),'Test that test file is no longer tracked');
211225

212-
213-
214-
215226
}
216227

217228

0 commit comments

Comments
 (0)