Skip to content

Commit 3b34aa0

Browse files
committed
fix Git\Reference testcase.
1 parent 8f8a12a commit 3b34aa0

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

tests/GitReferenceTest.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,17 @@
99

1010
class GitReferenceTest extends \PHPUnit_Framework_TestCase
1111
{
12+
public static $reference_name = "";
13+
14+
public static function setUpBeforeClass()
15+
{
16+
self::$reference_name = trim(preg_replace("/^ref: /","",file_get_contents(dirname(__DIR__) . "/.git/HEAD")));
17+
}
18+
1219
protected function setUp()
1320
{
1421
//this test still legacy. fix environment probrem soon
15-
$this->markTestSkipped();
22+
//$this->markTestSkipped();
1623
}
1724

1825
protected function tearDown()
@@ -26,7 +33,7 @@ protected function tearDown()
2633
public function testGitRefrenceCanResolve()
2734
{
2835
$rep = new Git\Repository(dirname(__DIR__) . "/.git/");
29-
$reference = $rep->lookupRef("refs/heads/develop");
36+
$reference = $rep->lookupRef(self::$reference_name);
3037
$this->assertInstanceof("Git\\Reference",$reference,"returned object does not Git\\Reference");
3138
}
3239

@@ -37,7 +44,7 @@ public function testGitRefrenceCanResolve()
3744
public function testGitReferenceCanUseGetType()
3845
{
3946
$rep = new Git\Repository(dirname(__DIR__) . "/.git/");
40-
$ref = $rep->lookupRef("refs/heads/develop");
47+
$ref = $rep->lookupRef(self::$reference_name);
4148
$type = $ref->getType();
4249
$this->assertEquals(1,$type,"illegal reference type returned.(this is legacy test. check test file)");
4350
}
@@ -48,10 +55,10 @@ public function testGitReferenceCanUseGetType()
4855
public function testGitReferenceGetName()
4956
{
5057
$rep = new Git\Repository(dirname(__DIR__) . "/.git/");
51-
$ref = $rep->lookupRef("refs/heads/develop");
58+
$ref = $rep->lookupRef(self::$reference_name);
5259
$name = $ref->getName();
5360

54-
$this->assertEquals("refs/heads/develop",$name,"reference name missmatched.");
61+
$this->assertEquals(self::$reference_name,$name,"reference name missmatched.");
5562
}
5663

5764
/**
@@ -60,7 +67,7 @@ public function testGitReferenceGetName()
6067
public function testGitReferenceGetId()
6168
{
6269
$rep = new Git\Repository(dirname(__DIR__) . "/.git/");
63-
$ref = $rep->lookupRef("refs/heads/develop");
70+
$ref = $rep->lookupRef(self::$reference_name);
6471
$id = $ref->getId();
6572

6673
$this->assertEquals(40,strlen($id),"illegal oid size returned");
@@ -73,7 +80,7 @@ public function testGitReferenceGetId()
7380
public function testGitReferenceGetTarget()
7481
{
7582
$rep = new Git\Repository(dirname(__DIR__) . "/.git/");
76-
$ref = $rep->lookupRef("refs/heads/develop");
83+
$ref = $rep->lookupRef(self::$reference_name);
7784
try{
7885
$target = $ref->getTarget();
7986
$this->fail("something wrong. this method allowed symbolic reference only.");

tests/GitTest.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323

2424
class GitTest extends \PHPUnit_Framework_TestCase
2525
{
26+
public static $reference_name = "";
27+
28+
public static function setUpBeforeClass()
29+
{
30+
self::$reference_name = trim(preg_replace("/^ref: /","",file_get_contents(dirname(__DIR__) . "/.git/HEAD")));
31+
}
32+
2633
protected function setUp()
2734
{
2835
// currentry nothing to do.
@@ -35,16 +42,12 @@ protected function tearDown()
3542

3643
public function testLookupRef()
3744
{
38-
//this test still legacy. fix environment probrem soon
39-
$this->markTestSkipped();
40-
41-
//temporary added Git\\Reference.
4245
$git = new Git\Repository(dirname(__DIR__) . "/.git/");
43-
$ref = $git->lookupRef("refs/heads/master");
44-
$commit = $git->getCommit($ref->oid);
46+
$ref = $git->lookupRef(self::$reference_name);
47+
$commit = $git->getCommit($ref->getId());
4548

46-
$this->assertInstanceof("Git\\Reference",$ref,"Git\\Referenceが帰ってきているか?");
47-
$this->assertInstanceof("Git\\Commit",$commit,"Git\\Commitが帰ってきているか?");
49+
$this->assertInstanceof("Git\\Reference",$ref,"can't lookup reference");
50+
$this->assertInstanceof("Git\\Commit",$commit,"reference can't return commit object");
4851
}
4952

5053

@@ -120,7 +123,7 @@ public function testGetIndex()
120123
public function testInitRepository()
121124
{
122125
require_once __DIR__ . "/lib/MemoryBackend.php";
123-
require_once __DIR__ . "/lib/MemcachedBackend.php";
126+
//require_once __DIR__ . "/lib/MemcachedBackend.php";
124127

125128

126129
$this->rmdir(__DIR__ . "/git_init_test");
@@ -164,6 +167,7 @@ public function testInitRepository()
164167

165168
//$this->markTestIncomplete("this test does not implemente yet.");
166169
$this->assertEquals("c12883a96cf60d1b2edba971183ffaca6d1b077e",$master_hash,"commit writing");
170+
167171
/*
168172
$re = new Git\Reference($repository);
169173
$re->setName("refs/heads/master");

0 commit comments

Comments
 (0)