1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Test case |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2007-2010, Mayflower GmbH |
7
|
|
|
* All rights reserved. |
8
|
|
|
* |
9
|
|
|
* Redistribution and use in source and binary forms, with or without |
10
|
|
|
* modification, are permitted provided that the following conditions |
11
|
|
|
* are met: |
12
|
|
|
* |
13
|
|
|
* * Redistributions of source code must retain the above copyright |
14
|
|
|
* notice, this list of conditions and the following disclaimer. |
15
|
|
|
* |
16
|
|
|
* * Redistributions in binary form must reproduce the above copyright |
17
|
|
|
* notice, this list of conditions and the following disclaimer in |
18
|
|
|
* the documentation and/or other materials provided with the |
19
|
|
|
* distribution. |
20
|
|
|
* |
21
|
|
|
* * Neither the name of Mayflower GmbH nor the names of his |
22
|
|
|
* contributors may be used to endorse or promote products derived |
23
|
|
|
* from this software without specific prior written permission. |
24
|
|
|
* |
25
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
26
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
27
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
28
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
29
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
30
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
31
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
32
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
33
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
34
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
35
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
36
|
|
|
* POSSIBILITY OF SUCH DAMAGE. |
37
|
|
|
* |
38
|
|
|
* @category PHP_CodeBrowser |
39
|
|
|
* |
40
|
|
|
* @author Simon Kohlmeyer <[email protected] |
41
|
|
|
* |
42
|
|
|
* @copyright 2007-2010 Mayflower GmbH |
43
|
|
|
* |
44
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
45
|
|
|
* |
46
|
|
|
* @version SVN: $Id$ |
47
|
|
|
* |
48
|
|
|
* @link http://www.phpunit.de/ |
49
|
|
|
* |
50
|
|
|
* @since File available since 0.1.0 |
51
|
|
|
*/ |
52
|
|
|
|
53
|
|
|
namespace PHPCodeBrowser\Tests; |
54
|
|
|
|
55
|
|
|
use Monolog\Logger; |
56
|
|
|
use PHPCodeBrowser\CLIController; |
57
|
|
|
use PHPCodeBrowser\Helper\IOHelper; |
58
|
|
|
use PHPCodeBrowser\Plugins\ErrorCRAP; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* CLIControllerTest |
62
|
|
|
* |
63
|
|
|
* @category PHP_CodeBrowser |
64
|
|
|
* |
65
|
|
|
* @author Simon Kohlmeyer <[email protected]> |
66
|
|
|
* |
67
|
|
|
* @copyright 2007-2010 Mayflower GmbH |
68
|
|
|
* |
69
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
70
|
|
|
* |
71
|
|
|
* @version Release: @package_version@ |
72
|
|
|
* |
73
|
|
|
* @link http://www.phpunit.de/ |
74
|
|
|
* |
75
|
|
|
* @since Class available since 0.1.0 |
76
|
|
|
*/ |
77
|
|
|
class CLIControllerTest extends AbstractTestCase |
78
|
|
|
{ |
79
|
|
|
/** |
80
|
|
|
* @var CLIController $controller |
81
|
|
|
*/ |
82
|
|
|
private $controller; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Create and configure a CLIController instance. |
86
|
|
|
*/ |
87
|
|
|
public function setUp(): void |
88
|
|
|
{ |
89
|
|
|
parent::setUp(); |
90
|
|
|
|
91
|
|
|
$this->controller = new CLIController( |
92
|
|
|
null, |
93
|
|
|
[self::$phpcbSourceDir], |
94
|
|
|
self::$testOutputDir, |
95
|
|
|
[], |
96
|
|
|
[], |
97
|
|
|
[ErrorCRAP::class => ['threshold' => 1]], |
98
|
|
|
new IOHelper(), |
99
|
|
|
new Logger('PHPCodeBrowser'), |
100
|
|
|
['php'] |
101
|
|
|
); |
102
|
|
|
|
103
|
|
|
$this->controller->addErrorPlugins( |
104
|
|
|
[ |
105
|
|
|
'ErrorCheckstyle', |
106
|
|
|
'ErrorPMD', |
107
|
|
|
'ErrorCPD', |
108
|
|
|
'ErrorPadawan', |
109
|
|
|
'ErrorCoverage', |
110
|
|
|
'ErrorCRAP', |
111
|
|
|
] |
112
|
|
|
); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Assert a set of directories and files are present in output dir. |
117
|
|
|
*/ |
118
|
|
|
public function assertOutputIsPresent(): void |
119
|
|
|
{ |
120
|
|
|
self::assertFileExists(self::$testOutputDir.'/index.html'); |
121
|
|
|
self::assertFileExists(self::$testOutputDir.'/Bad.php.html'); |
122
|
|
|
self::assertFileExists(self::$testOutputDir.'/Good.php.html'); |
123
|
|
|
self::assertDirectoryExists(self::$testOutputDir.'/css'); |
124
|
|
|
self::assertDirectoryExists(self::$testOutputDir.'/img'); |
125
|
|
|
self::assertDirectoryExists(self::$testOutputDir.'/js'); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Run a full system test based on phpcs output. |
130
|
|
|
*/ |
131
|
|
|
public function testRunCreatesFilesAndDirs(): void |
132
|
|
|
{ |
133
|
|
|
$this->controller->run(); |
134
|
|
|
|
135
|
|
|
$this->assertOutputIsPresent(); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Assert existing files and directories within output dir are removed. |
140
|
|
|
*/ |
141
|
|
|
public function testRunCleansExistingOutputDir(): void |
142
|
|
|
{ |
143
|
|
|
\mkdir(self::$testOutputDir.'/clear-directory'); |
144
|
|
|
\touch(self::$testOutputDir.'/clear-file'); |
145
|
|
|
\touch(self::$testOutputDir.'/clear-directory/clear-file'); |
146
|
|
|
|
147
|
|
|
$this->controller->run(); |
148
|
|
|
|
149
|
|
|
$this->assertOutputIsPresent(); |
150
|
|
|
static::assertDirectoryDoesNotExist(self::$testOutputDir.'/clear-directory'); |
151
|
|
|
static::assertFileDoesNotExist(self::$testOutputDir.'/clear-file'); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Assert that if there is a file with outputs name, it is replaced with a directory. |
156
|
|
|
*/ |
157
|
|
|
public function testRunCleansExistingOutputFile(): void |
158
|
|
|
{ |
159
|
|
|
\rmdir(self::$testOutputDir); |
160
|
|
|
\touch(self::$testOutputDir); |
161
|
|
|
|
162
|
|
|
$this->controller->run(); |
163
|
|
|
|
164
|
|
|
$this->assertOutputIsPresent(); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Assert only index.html is present if all source files are excluded. |
169
|
|
|
*/ |
170
|
|
|
public function testRunExcludingAllSources(): void |
171
|
|
|
{ |
172
|
|
|
$this->controller = new CLIController( |
173
|
|
|
null, |
174
|
|
|
[self::$phpcbSourceDir], |
175
|
|
|
self::$testOutputDir, |
176
|
|
|
['/Bad.php/'], |
177
|
|
|
['*Good.php'], |
178
|
|
|
[ErrorCRAP::class => ['threshold' => 1]], |
179
|
|
|
new IOHelper(), |
180
|
|
|
new Logger('PHPCodeBrowser'), |
181
|
|
|
['php'] |
182
|
|
|
); |
183
|
|
|
|
184
|
|
|
$this->controller->run(); |
185
|
|
|
|
186
|
|
|
static::assertFileExists(self::$testOutputDir.'/index.html'); |
187
|
|
|
static::assertFileDoesNotExist(self::$testOutputDir.'/Bad.php.html'); |
188
|
|
|
static::assertFileDoesNotExist(self::$testOutputDir.'/Good.php.html'); |
189
|
|
|
static::assertDirectoryDoesNotExist(self::$testOutputDir.'/css'); |
190
|
|
|
static::assertDirectoryDoesNotExist(self::$testOutputDir.'/img'); |
191
|
|
|
static::assertDirectoryDoesNotExist(self::$testOutputDir.'/js'); |
192
|
|
|
} |
193
|
|
|
} |
194
|
|
|
|