Completed
Pull Request — develop (#163)
by
unknown
16:20
created

testExceptionWhenCallingMergeWithConflictingFfArguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
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(): void
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(): void
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
    public function testExceptionWhenCallingMergeWithConflictingFfArguments(): void
49
    {
50
        $branch = $this->getRepository()->getBranch('test');
51
        $this->expectException(\Symfony\Component\Process\Exception\InvalidArgumentException::class);
52
        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 50 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...
53
    }
54
}
55