Completed
Pull Request — develop (#100)
by
unknown
03:44
created

MergeCommandTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 5
Bugs 0 Features 1
Metric Value
wmc 3
c 5
b 0
f 1
lcom 1
cbo 3
dl 0
loc 38
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 8 1
A testMerge() 0 9 1
A test_exception_when_calling_merge_with_conflicting_ff_arguments() 0 5 1
1
<?php
2
/**
3
 * User: matteo
4
 * Date: 28/05/13
5
 * Time: 18.36
6
 * Just for fun...
7
 */
8
9
namespace GitElephant\Command;
10
11
use \GitElephant\TestCase;
12
13
/**
14
 * Class MergeCommandTest
15
 *
16
 * @package GitElephant\Command
17
 */
18
class MergeCommandTest extends TestCase
19
{
20
    /**
21
     * setUp
22
     */
23
    public function setUp()
24
    {
25
        $this->initRepository();
26
        $this->getRepository()->init();
27
        $this->addFile('test');
28
        $this->getRepository()->commit('test', true);
29
        $this->getRepository()->createBranch('test', 'master');
30
    }
31
32
    /**
33
     * testMerge
34
     */
35
    public function testMerge()
36
    {
37
        $mc     = MergeCommand::getInstance();
38
        $branch = $this->getRepository()->getBranch('test');
39
        $this->assertEquals("merge 'refs/heads/test'", $mc->merge($branch));
0 ignored issues
show
Bug introduced by
It seems like $branch defined by $this->getRepository()->getBranch('test') on line 38 can be null; however, GitElephant\Command\MergeCommand::merge() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
40
        $this->assertEquals("merge '-m' 'test msg' 'refs/heads/test'", $mc->merge($branch, "test msg"));
0 ignored issues
show
Bug introduced by
It seems like $branch defined by $this->getRepository()->getBranch('test') on line 38 can be null; however, GitElephant\Command\MergeCommand::merge() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
41
        $this->assertEquals("merge '--ff-only' '-m' 'test msg' 'refs/heads/test'", $mc->merge($branch, "test msg", array('--ff-only')));
0 ignored issues
show
Bug introduced by
It seems like $branch defined by $this->getRepository()->getBranch('test') on line 38 can be null; however, GitElephant\Command\MergeCommand::merge() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
42
        $this->assertEquals("merge '--no-ff' '-m' 'test msg' 'refs/heads/test'", $mc->merge($branch, "test msg", array('--no-ff')));
0 ignored issues
show
Bug introduced by
It seems like $branch defined by $this->getRepository()->getBranch('test') on line 38 can be null; however, GitElephant\Command\MergeCommand::merge() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
43
    }
44
45
    /**
46
     * MergeCommand should throw an exception when both --ff-only and --no-ff flags were set.
47
     *
48
     * @expectedException \Symfony\Component\Process\Exception\InvalidArgumentException
49
     */
50
    public function test_exception_when_calling_merge_with_conflicting_ff_arguments()
51
    {
52
        $branch = $this->getRepository()->getBranch('test');
53
        MergeCommand::getInstance()->merge($branch, "test msg", array('--ff-only', '--no-ff'));
0 ignored issues
show
Bug introduced by
It seems like $branch defined by $this->getRepository()->getBranch('test') on line 52 can be null; however, GitElephant\Command\MergeCommand::merge() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
54
    }
55
}
56