Skip to content

Commit e30b70b

Browse files
committed
Move test repo to system tmp dir, introduce phpGitRepoCommand
1 parent 01fabb1 commit e30b70b

5 files changed

+62
-13
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
nbproject
2-
test/repo/.git

lib/phpGitRepo.php

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* Tickets: http://github.com/ornicar/php-git-repo/issues
1313
*/
1414

15+
require_once(dirname(__FILE__).'/phpGitRepoCommand.php');
16+
1517
class phpGitRepo
1618
{
1719
/**

lib/phpGitRepoCommand.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
class phpGitRepoCommand
4+
{
5+
protected $dir;
6+
7+
protected $command;
8+
9+
public function __construct($dir, $command)
10+
{
11+
$this->dir = $dir;
12+
$this->command = $command;
13+
}
14+
15+
public function run()
16+
{
17+
18+
}
19+
}

test/phpGitRepoTest.php

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
<?php
22

33
require_once dirname(__FILE__).'/vendor/lime.php';
4-
require_once dirname(__FILE__).'/../lib/phpGitRepo.php';
4+
require_once dirname(__FILE__).'/phpGitRepoTestHelper.php';
55

66
$t = new lime_test();
77

8-
$nonExistingDir = '/non/existing/directory';
9-
$message = $nonExistingDir.' is not a valid git repository';
10-
try
11-
{
12-
new phpGitRepo($nonExistingDir);
13-
$t->fail($message);
14-
}
15-
catch(InvalidArgumentException $e)
16-
{
17-
$t->pass($message);
18-
}
8+
$repo = _createTmpGitRepo($t);

test/phpGitRepoTestHelper.php

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
require_once dirname(__FILE__).'/../lib/phpGitRepo.php';
4+
5+
/**
6+
*
7+
* @param lime_test $t
8+
* @return phpGitRepo the git repo
9+
*/
10+
function _createTmpGitRepo(lime_test $t)
11+
{
12+
$repoDir = sys_get_temp_dir().'/php-git-repo/'.uniqid();
13+
$t->ok(!is_dir($repoDir.'/.git'), $repoDir.' is not a Git repo');
14+
15+
try
16+
{
17+
new phpGitRepo($repoDir);
18+
$t->fail($repoDir.' is not a valid git repository');
19+
}
20+
catch(InvalidArgumentException $e)
21+
{
22+
$t->pass($repoDir.' is not a valid git repository');
23+
}
24+
25+
$t->comment('Create Git repo');
26+
exec('git init '. escapeshellarg($repoDir.'/.git'));
27+
$t->ok(is_dir($repoDir.'/.git'), $repoDir.' is a Git repo');
28+
29+
$repo = new phpGitRepo($repoDir);
30+
$t->pass($repoDir.' is a valid git repo');
31+
32+
$originalRepoDir = dirname(__FILE__).'/repo';
33+
foreach(array('README.markdown', 'index.php') as $file)
34+
{
35+
copy($originalRepoDir.'/'.$file, $repoDir.'/'.$file);
36+
}
37+
38+
return $repo;
39+
}

0 commit comments

Comments
 (0)