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

MergeCommandTest::testMerge()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 1
Metric Value
c 4
b 0
f 1
dl 0
loc 9
rs 9.6666
cc 1
eloc 7
nc 1
nop 0
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