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() |
|
|
|
|
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'); |
|
|
|
|
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() |
|
|
|
|
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'); |
|
|
|
|
62
|
|
|
|
63
|
|
|
$this->assertContains('Action seems illegal', $output); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
View Code Duplication |
public function testPullNonAuthorizedProject() |
|
|
|
|
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'); |
|
|
|
|
78
|
|
|
|
79
|
|
|
$this->assertContains('You are not allowed', $output); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
View Code Duplication |
public function testPullAuthorizedProject() |
|
|
|
|
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'); |
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
96
|
|
View Code Duplication |
public function testPushNonAuthorizedProject() |
|
|
|
|
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'); |
|
|
|
|
108
|
|
|
|
109
|
|
|
$this->assertContains('You are not allowed', $output); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
View Code Duplication |
public function testPushAuthorizedProject() |
|
|
|
|
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'); |
|
|
|
|
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
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.