TagTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 64
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testTag() 0 12 1
A testTagFromStartPoint() 0 14 1
A testNonExistentTag() 0 9 1
A testCreate() 0 11 1
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());
0 ignored issues
show
Bug introduced by
It seems like $this->repository can also be of type array<integer,object<GitElephant\Repository>>; however, GitElephant\Objects\Tag::create() does only seem to accept object<GitElephant\Repository>, maybe add an additional type check?

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:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
42
        $tag = new Tag($this->repository, 'tag1');
0 ignored issues
show
Bug introduced by
It seems like $this->repository can also be of type array<integer,object<GitElephant\Repository>>; however, GitElephant\Objects\Tag::__construct() does only seem to accept object<GitElephant\Repository>, maybe add an additional type check?

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:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
43
        $this->assertInstanceOf('GitElephant\Objects\Tag', $tag);
44
        $this->assertEquals($tag->getSha(), $this->repository->getCommit()->getSha());
45
        $branch = Branch::create($this->repository, 'test-branch');
0 ignored issues
show
Bug introduced by
It seems like $this->repository can also be of type array<integer,object<GitElephant\Repository>>; however, GitElephant\Objects\Branch::create() does only seem to accept object<GitElephant\Repository>, maybe add an additional type check?

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:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
46
        Tag::create($this->repository, 'tag2', $branch);
0 ignored issues
show
Bug introduced by
It seems like $this->repository can also be of type array<integer,object<GitElephant\Repository>>; however, GitElephant\Objects\Tag::create() does only seem to accept object<GitElephant\Repository>, maybe add an additional type check?

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:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
47
        $tag = new Tag($this->repository, 'tag2');
0 ignored issues
show
Bug introduced by
It seems like $this->repository can also be of type array<integer,object<GitElephant\Repository>>; however, GitElephant\Objects\Tag::__construct() does only seem to accept object<GitElephant\Repository>, maybe add an additional type check?

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:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
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');
0 ignored issues
show
Bug introduced by
It seems like $this->repository can also be of type array<integer,object<GitElephant\Repository>>; however, GitElephant\Objects\Tag::create() does only seem to accept object<GitElephant\Repository>, maybe add an additional type check?

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:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
74
        $this->assertCount(1, $this->repository->getTags());
75
        Tag::create($this->repository, 'test-tag2', 'test-tag');
0 ignored issues
show
Bug introduced by
It seems like $this->repository can also be of type array<integer,object<GitElephant\Repository>>; however, GitElephant\Objects\Tag::create() does only seem to accept object<GitElephant\Repository>, maybe add an additional type check?

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:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
76
        $this->assertCount(2, $this->repository->getTags());
77
    }
78
}
79