Permalink
Browse files

Added testing for tree

  • Loading branch information...
gamort committed May 13, 2014
1 parent 7c5a25b commit 03a8c4c586e1de71f3d033cdb3f5aea136ce61ea
Showing with 89 additions and 0 deletions.
  1. +52 −0 tests/init.php
  2. +37 −0 tests/tree/git_tree_lookup.phpt
View
@@ -0,0 +1,52 @@
<?php
function recurse_copy($src,$dst) {
$dir = opendir($src);
@mkdir($dst);
while(false !== ( $file = readdir($dir)) ) {
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir($src . '/' . $file) ) {
recurse_copy($src . '/' . $file,$dst . '/' . $file);
}
else {
copy($src . '/' . $file,$dst . '/' . $file);
}
}
}
closedir($dir);
}
function init_repo($reponame, $target, $bare = false)
{
$rootPath = dirname(__DIR__);
$libgitPath = $rootPath . '/libgit2';
$testRepoPath = $libgitPath . '/tests/resources';
if (!file_exists($testRepoPath))
{
throw new Exception('test repository assets not found at '.$testRepoPath);
}
$repoPath = $testRepoPath . '/' . $reponame;
if (!file_exists($repoPath))
{
throw new Exception('test repository '. $reponame.' assets not found');
}
@mkdir($target);
recurse_copy($repoPath, $target.'/'.$reponame);
if (!$bare)
{
$oldPath =$target.'/'.$reponame.'/.gitted';
$newPath =$target.'/'.$reponame.'/.git';
rename($oldPath, $newPath);
}
}
@@ -0,0 +1,37 @@
--TEST--
Check for git_tree_lookup
--SKIPIF--
<?php if (!extension_loaded("git2")) print "skip"; ?>
--FILE--
<?php
include_once(__DIR__ . '/../init.php');
$path = "/tmp/git-tree-lookup";
$testRepo = 'testrepo';
init_Repo($testRepo, $path);
$repositroy = git_repository_open($path . '/' . $testRepo);
$fileHash = '6336846bd5c88d32f93ae57d846683e61ab5c530';
$treeHash = '1810dff58d8a660512d4832e740f692884338ccd';
$tree = git_tree_lookup($repositroy, $treeHash);
if (is_resource($tree)) {
echo "TREE: $treeHash OK" . PHP_EOL;
}
else
{
echo "TREE: $treeHash FAIL" . PHP_EOL;
}
$tree = @git_tree_lookup($repositroy, $fileHash);
if ($tree===null) {
echo "FILE: $fileHash OK" . PHP_EOL;
}
else
{
echo "FILE: $fileHash FAIL" . PHP_EOL;
}
--EXPECT--
TREE: 1810dff58d8a660512d4832e740f692884338ccd OK
FILE: 6336846bd5c88d32f93ae57d846683e61ab5c530 FAIL

0 comments on commit 03a8c4c

Please sign in to comment.