1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* User: matteo |
5
|
|
|
* Date: 28/10/12 |
6
|
|
|
* Time: 16.16 |
7
|
|
|
* |
8
|
|
|
* Just for fun... |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace GitElephant\Objects; |
12
|
|
|
|
13
|
|
|
use GitElephant\TestCase; |
14
|
|
|
|
15
|
|
|
class TagTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* testTag |
19
|
|
|
*/ |
20
|
|
|
public function testTag(): void |
21
|
|
|
{ |
22
|
|
|
$this->getRepository()->init(); |
23
|
|
|
$this->addFile('foo'); |
24
|
|
|
$this->getRepository()->commit('commit1', true); |
25
|
|
|
$this->getRepository()->createTag('test-tag'); |
26
|
|
|
$tag = new Tag($this->getRepository(), 'test-tag'); |
27
|
|
|
$this->assertInstanceOf('GitElephant\Objects\Tag', $tag); |
28
|
|
|
$this->assertEquals('test-tag', $tag->getName()); |
29
|
|
|
$this->assertEquals('refs/tags/test-tag', $tag->getFullRef()); |
30
|
|
|
$this->assertEquals($this->getRepository()->getCommit()->getSha(), $tag->getSha()); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* testTagFromStartPoint |
35
|
|
|
*/ |
36
|
|
|
public function testTagFromStartPoint(): void |
37
|
|
|
{ |
38
|
|
|
$this->getRepository()->init(); |
39
|
|
|
$this->addFile('foo'); |
40
|
|
|
$this->repository->commit('commit1', true); |
41
|
|
|
Tag::create($this->repository, 'tag1', $this->repository->getCommit()); |
|
|
|
|
42
|
|
|
$tag = new Tag($this->repository, 'tag1'); |
|
|
|
|
43
|
|
|
$this->assertInstanceOf('GitElephant\Objects\Tag', $tag); |
44
|
|
|
$this->assertEquals($tag->getSha(), $this->repository->getCommit()->getSha()); |
45
|
|
|
$branch = Branch::create($this->repository, 'test-branch'); |
|
|
|
|
46
|
|
|
Tag::create($this->repository, 'tag2', $branch); |
|
|
|
|
47
|
|
|
$tag = new Tag($this->repository, 'tag2'); |
|
|
|
|
48
|
|
|
$this->assertEquals($tag->getSha(), $branch->getSha()); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* testNonExistentTag |
53
|
|
|
*/ |
54
|
|
|
public function testNonExistentTag(): void |
55
|
|
|
{ |
56
|
|
|
$this->expectException(\InvalidArgumentException::class); |
57
|
|
|
$this->getRepository()->init(); |
58
|
|
|
$this->addFile('foo'); |
59
|
|
|
$this->getRepository()->commit('commit1', true); |
60
|
|
|
$this->getRepository()->createTag('test-tag'); |
61
|
|
|
new Tag($this->getRepository(), 'test-tag-non-existent'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* testCreate |
66
|
|
|
*/ |
67
|
|
|
public function testCreate(): void |
68
|
|
|
{ |
69
|
|
|
$this->getRepository()->init(); |
70
|
|
|
$this->addFile('test'); |
71
|
|
|
$this->repository->commit('test', true); |
72
|
|
|
$this->assertCount(0, $this->repository->getTags()); |
73
|
|
|
Tag::create($this->repository, 'test-tag'); |
|
|
|
|
74
|
|
|
$this->assertCount(1, $this->repository->getTags()); |
75
|
|
|
Tag::create($this->repository, 'test-tag2', 'test-tag'); |
|
|
|
|
76
|
|
|
$this->assertCount(2, $this->repository->getTags()); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.