1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of CaptainHook. |
4
|
|
|
* |
5
|
|
|
* (c) Sebastian Feldmann <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
namespace CaptainHook\Git; |
11
|
|
|
|
12
|
|
|
class RepositoryTest extends \PHPUnit_Framework_TestCase |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var \CaptainHook\Git\DummyRepo |
16
|
|
|
*/ |
17
|
|
|
private $repo; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Setup dummy repo. |
21
|
|
|
*/ |
22
|
|
|
public function setUp() |
23
|
|
|
{ |
24
|
|
|
$this->repo = new DummyRepo(); |
25
|
|
|
$this->repo->setup(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Cleanup dummy repo. |
30
|
|
|
*/ |
31
|
|
|
public function tearDown() |
32
|
|
|
{ |
33
|
|
|
$this->repo->cleanup(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Tests Repository::__construct |
38
|
|
|
* |
39
|
|
|
* @expectedException \Exception |
40
|
|
|
*/ |
41
|
|
|
public function testInvalidRepository() |
42
|
|
|
{ |
43
|
|
|
$repository = new Repository('invalidGitRepo'); |
44
|
|
|
$this->assertFalse(is_a($repository, '\\CaptainHook\\Git\\Repository')); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Tests Repository::getHooks |
49
|
|
|
*/ |
50
|
|
|
public function testGetHooksDir() |
51
|
|
|
{ |
52
|
|
|
$repository = new Repository($this->repo->getPath()); |
53
|
|
|
$this->assertEquals($this->repo->getPath() . '/.git/hooks', $repository->getHooksDir()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Tests Repository::hookExists |
58
|
|
|
*/ |
59
|
|
|
public function testHookExists() |
60
|
|
|
{ |
61
|
|
|
$this->repo->touchHook('pre-commit'); |
62
|
|
|
|
63
|
|
|
$repository = new Repository($this->repo->getPath()); |
64
|
|
|
|
65
|
|
|
$this->assertTrue($repository->hookExists('pre-commit')); |
66
|
|
|
$this->assertFalse($repository->hookExists('pre-push')); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Tests Repository::getCommitMsg |
71
|
|
|
* |
72
|
|
|
* @expectedException \Exception |
73
|
|
|
*/ |
74
|
|
|
public function testGetCommitMessageFail() |
75
|
|
|
{ |
76
|
|
|
$repository = new Repository($this->repo->getPath()); |
77
|
|
|
$repository->getCommitMsg(); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|