Skip to content
This repository has been archived by the owner on Oct 1, 2021. It is now read-only.

Commit

Permalink
Move test repo to system tmp dir, introduce phpGitRepoCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Apr 14, 2010
1 parent 01fabb1 commit e30b70b
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 13 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
nbproject
test/repo/.git
2 changes: 2 additions & 0 deletions lib/phpGitRepo.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* Tickets: http://github.com/ornicar/php-git-repo/issues
*/

require_once(dirname(__FILE__).'/phpGitRepoCommand.php');

class phpGitRepo
{
/**
Expand Down
19 changes: 19 additions & 0 deletions lib/phpGitRepoCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

class phpGitRepoCommand
{
protected $dir;

protected $command;

public function __construct($dir, $command)
{
$this->dir = $dir;
$this->command = $command;
}

public function run()
{

}
}
14 changes: 2 additions & 12 deletions test/phpGitRepoTest.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
<?php

require_once dirname(__FILE__).'/vendor/lime.php';
require_once dirname(__FILE__).'/../lib/phpGitRepo.php';
require_once dirname(__FILE__).'/phpGitRepoTestHelper.php';

$t = new lime_test();

$nonExistingDir = '/non/existing/directory';
$message = $nonExistingDir.' is not a valid git repository';
try
{
new phpGitRepo($nonExistingDir);
$t->fail($message);
}
catch(InvalidArgumentException $e)
{
$t->pass($message);
}
$repo = _createTmpGitRepo($t);
39 changes: 39 additions & 0 deletions test/phpGitRepoTestHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

require_once dirname(__FILE__).'/../lib/phpGitRepo.php';

/**
*
* @param lime_test $t
* @return phpGitRepo the git repo
*/
function _createTmpGitRepo(lime_test $t)
{
$repoDir = sys_get_temp_dir().'/php-git-repo/'.uniqid();
$t->ok(!is_dir($repoDir.'/.git'), $repoDir.' is not a Git repo');

try
{
new phpGitRepo($repoDir);
$t->fail($repoDir.' is not a valid git repository');
}
catch(InvalidArgumentException $e)
{
$t->pass($repoDir.' is not a valid git repository');
}

$t->comment('Create Git repo');
exec('git init '. escapeshellarg($repoDir.'/.git'));
$t->ok(is_dir($repoDir.'/.git'), $repoDir.' is a Git repo');

$repo = new phpGitRepo($repoDir);
$t->pass($repoDir.' is a valid git repo');

$originalRepoDir = dirname(__FILE__).'/repo';
foreach(array('README.markdown', 'index.php') as $file)
{
copy($originalRepoDir.'/'.$file, $repoDir.'/'.$file);
}

return $repo;
}

0 comments on commit e30b70b

Please sign in to comment.