Completed
Push — master ( a5a038...08ae9a )
by Ricardo
04:34
created

GitCommandTest::testPullAuthorizedProject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 14
Ratio 107.69 %

Importance

Changes 0
Metric Value
dl 14
loc 13
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * This file is part of Fabrica.
5
 *
6
 * (c) Alexandre Salomé <[email protected]>
7
 * (c) Julien DIDIER <[email protected]>
8
 *
9
 * This source file is subject to the GPL license that is bundled
10
 * with this source code in the file LICENSE.
11
 */
12
13
namespace Fabrica\Bundle\CoreBundle\Tests\Command;
14
15
use Fabrica\Bundle\CoreBundle\Test\CommandTestCase;
16
17
class GitCommandTest extends CommandTestCase
18
{
19
    protected $client;
20
21
    protected $shellHandler;
22
23
    protected function setUp(): void
24
    {
25
        $this->client = self::createClient();
26
27
        $this->shellHandler = $this->getMockBuilder('Fabrica\Bundle\CoreBundle\Git\ShellHandler')
28
            ->disableOriginalConstructor()
29
            ->getMock();
30
        $this->client->setShellHandler($this->shellHandler);
31
32
        $this->client->startIsolation();
33
    }
34
35
    public function tearDown(): void
36
    {
37
        $this->client->stopIsolation();
38
    }
39
40 View Code Duplication
    public function testShellInformation()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
    {
42
        $this->shellHandler
43
            ->expects($this->once())
44
            ->method('getOriginalCommand')
45
            ->will($this->returnValue(null));
46
47
        list($statusCode ,$output) = $this->runCommand($this->client, 'fabrica:git --stderr=no alice');
0 ignored issues
show
Unused Code introduced by
The assignment to $statusCode is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
48
49
        $this->assertContains('You are identified as alice', $output);
50
        $this->assertRegexp('/Foobar[ ]+Developer[ ]/', $output);
51
        $this->assertRegexp('/Barbaz[ ]+Lead developer[ ]/', $output);
52
    }
53
54 View Code Duplication
    public function testIllegalAction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
    {
56
        $this->shellHandler
57
            ->expects($this->once())
58
            ->method('getOriginalCommand')
59
            ->will($this->returnValue('git-bla-pack \'foobar.git\''));
60
61
        list($statusCode ,$output) = $this->runCommand($this->client, 'fabrica:git --stderr=no alice');
0 ignored issues
show
Unused Code introduced by
The assignment to $statusCode is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
62
63
        $this->assertContains('Action seems illegal', $output);
64
    }
65
66 View Code Duplication
    public function testPullNonAuthorizedProject()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
67
    {
68
        $this->shellHandler
69
            ->expects($this->once())
70
            ->method('getOriginalCommand')
71
            ->will($this->returnValue('git-upload-pack \'barbaz.git\''));
72
73
        $this->shellHandler
74
            ->expects($this->never())
75
            ->method('handle');
76
77
        list($statusCode ,$output) = $this->runCommand($this->client, 'fabrica:git --stderr=no bob');
0 ignored issues
show
Unused Code introduced by
The assignment to $statusCode is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
78
79
        $this->assertContains('You are not allowed', $output);
80
    }
81
82 View Code Duplication
    public function testPullAuthorizedProject()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
83
    {
84
        $this->shellHandler
85
            ->expects($this->once())
86
            ->method('getOriginalCommand')
87
            ->will($this->returnValue('git-upload-pack \'foobar.git\''));
88
89
        $this->shellHandler
90
            ->expects($this->once())
91
            ->method('handle');
92
93
        list($statusCode ,$output) = $this->runCommand($this->client, 'fabrica:git --stderr=no bob');
0 ignored issues
show
Unused Code introduced by
The assignment to $output is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
Unused Code introduced by
The assignment to $statusCode is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
94
    }
95
96 View Code Duplication
    public function testPushNonAuthorizedProject()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
97
    {
98
        $this->shellHandler
99
            ->expects($this->once())
100
            ->method('getOriginalCommand')
101
            ->will($this->returnValue('git-receive-pack \'barbaz.git\''));
102
103
        $this->shellHandler
104
            ->expects($this->never())
105
            ->method('handle');
106
107
        list($statusCode ,$output) = $this->runCommand($this->client, 'fabrica:git --stderr=no bob');
0 ignored issues
show
Unused Code introduced by
The assignment to $statusCode is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
108
109
        $this->assertContains('You are not allowed', $output);
110
    }
111
112 View Code Duplication
    public function testPushAuthorizedProject()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
113
    {
114
        $this->shellHandler
115
            ->expects($this->once())
116
            ->method('getOriginalCommand')
117
            ->will($this->returnValue('git-receive-pack \'foobar.git\''));
118
119
        $this->shellHandler
120
            ->expects($this->once())
121
            ->method('handle');
122
123
        list($statusCode ,$output) = $this->runCommand($this->client, 'fabrica:git --stderr=no bob');
0 ignored issues
show
Unused Code introduced by
The assignment to $statusCode is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
Unused Code introduced by
The assignment to $output is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
124
    }
125
}
126