Srokap /
code_review
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | namespace CodeReview\Tests; |
||
| 3 | |||
| 4 | class CodeReviewAnalyzerTest extends \PHPUnit_Framework_TestCase { |
||
| 5 | |||
| 6 | public function getLatestVersion($human_readable = false) { |
||
| 7 | return $human_readable ? '1.2' : 2015062900; |
||
| 8 | } |
||
| 9 | |||
| 10 | public function pluginsGetter($type) { |
||
|
0 ignored issues
–
show
|
|||
| 11 | return array( |
||
| 12 | 'injected_plugin', |
||
| 13 | 'ugly_plugin' |
||
| 14 | ); |
||
| 15 | } |
||
| 16 | |||
| 17 | public function setUp() { |
||
| 18 | $path = dirname(__FILE__) . '/test_files/fake_elgg/'; |
||
| 19 | |||
| 20 | require_once($path . 'engine/start.php'); |
||
| 21 | |||
| 22 | \code_review::initConfig(array( |
||
| 23 | 'path' => $path, |
||
| 24 | 'engine_path' => $path . 'engine/', |
||
| 25 | 'pluginspath' => $path . 'mod/', |
||
| 26 | 'plugins_getter' => array($this, 'pluginsGetter'), |
||
| 27 | )); |
||
| 28 | } |
||
| 29 | |||
| 30 | public function testPluginsGetter() { |
||
| 31 | $config = new \CodeReview\Config(array(), array($this, 'getLatestVersion')); |
||
| 32 | |||
| 33 | $this->assertEquals(array('injected_plugin', 'ugly_plugin'), $config->getPluginIds($config::T_PLUGINS_ACTIVE)); |
||
| 34 | |||
| 35 | $this->assertEquals(array('inactive_plugin'), $config->getPluginIds($config::T_PLUGINS_INACTIVE)); |
||
| 36 | |||
| 37 | $this->assertEquals(array('inactive_plugin', 'ugly_plugin'), $config->getPluginIds($config::T_PLUGINS_ALL)); |
||
| 38 | } |
||
| 39 | |||
| 40 | public function testAnalyzerFailOnBadPath() { |
||
| 41 | $config = new \CodeReview\Config(array(), array($this, 'getLatestVersion')); |
||
| 42 | $config->parseInput(array( |
||
| 43 | 'subpath' => 'does/not/exist', |
||
| 44 | 'version' => '1.2', |
||
| 45 | 'include_disabled_plugins' => false, |
||
| 46 | 'find_deprecated_functions' => true, |
||
| 47 | 'find_private_functions' => false, |
||
| 48 | 'fix_problems' => false, |
||
| 49 | )); |
||
| 50 | |||
| 51 | $generalConfig = \code_review::getConfig(); |
||
| 52 | $this->assertEquals(dirname(__FILE__) . '/test_files/fake_elgg/', $generalConfig['path']); |
||
| 53 | |||
| 54 | $analyzer = new \CodeReview\Analyzer($config); |
||
| 55 | $this->setExpectedException('CodeReview\IOException', "Invalid subPath specified. " . dirname(__FILE__) . "/test_files/fake_elgg/does/not/exist/ does not exists!"); |
||
| 56 | $analyzer->analyze(); |
||
| 57 | } |
||
| 58 | |||
| 59 | public function testAnalyzerNoFilesProcessed() { |
||
| 60 | $config = new \CodeReview\Config(array(), array($this, 'getLatestVersion')); |
||
| 61 | $config->parseInput(array( |
||
| 62 | 'subpath' => 'mod/inactive_plugin', |
||
| 63 | 'version' => '1.2', |
||
| 64 | 'include_disabled_plugins' => false, |
||
| 65 | 'find_deprecated_functions' => true, |
||
| 66 | 'find_private_functions' => false, |
||
| 67 | 'fix_problems' => false, |
||
| 68 | )); |
||
| 69 | |||
| 70 | $analyzer = new \CodeReview\Analyzer($config); |
||
| 71 | $analyzer->analyze(); |
||
| 72 | $stringOutput = $analyzer->outputReport(); |
||
| 73 | |||
| 74 | $this->assertContains("Subpath selected <strong>mod/inactive_plugin/</strong>", $stringOutput); |
||
| 75 | $this->assertContains("Max version: 1.2", $stringOutput); |
||
| 76 | $this->assertContains("Skipped inactive plugins: yes", $stringOutput); |
||
| 77 | $this->assertContains("Search for deprecated functions usage: yes", $stringOutput); |
||
| 78 | $this->assertContains("Search for private functions usage: no", $stringOutput); |
||
| 79 | $this->assertContains("Attempt to fix problems: no", $stringOutput); |
||
| 80 | $this->assertContains("Found 0 problems in 0 files", $stringOutput); |
||
| 81 | $this->assertContains("Found 0 fixes in 0 files", $stringOutput); |
||
| 82 | $this->assertContains("*** No files were processed! *** Analysis input parameters did not resolve to any files.", $stringOutput); |
||
| 83 | $this->assertNotContains("Time taken: ", $stringOutput); |
||
| 84 | } |
||
| 85 | |||
| 86 | public function testAnalysisActivePluginsNoPrivate12() { |
||
| 87 | $config = new \CodeReview\Config(array(), array($this, 'getLatestVersion')); |
||
| 88 | $config->parseInput(array( |
||
| 89 | 'subpath' => '', |
||
| 90 | 'version' => '1.2', |
||
| 91 | 'include_disabled_plugins' => false, |
||
| 92 | 'find_deprecated_functions' => true, |
||
| 93 | 'find_private_functions' => false, |
||
| 94 | 'fix_problems' => false, |
||
| 95 | )); |
||
| 96 | |||
| 97 | $analyzer = new \CodeReview\Analyzer($config); |
||
| 98 | $analyzer->analyze(); |
||
| 99 | $stringOutput = $analyzer->outputReport(); |
||
| 100 | |||
| 101 | $this->assertContains("Subpath selected <strong>/</strong>", $stringOutput); |
||
| 102 | $this->assertContains("Max version: 1.2", $stringOutput); |
||
| 103 | $this->assertContains("Skipped inactive plugins: yes", $stringOutput); |
||
| 104 | $this->assertContains("Search for deprecated functions usage: yes", $stringOutput); |
||
| 105 | $this->assertContains("Search for private functions usage: no", $stringOutput); |
||
| 106 | $this->assertContains("Attempt to fix problems: no", $stringOutput); |
||
| 107 | $this->assertContains("Found 2 problems in 2 files", $stringOutput); |
||
| 108 | $this->assertContains("Found 0 fixes in 2 files", $stringOutput); |
||
| 109 | $this->assertContains("Processed 12 files total", $stringOutput); |
||
| 110 | $this->assertNotContains("Time taken: ", $stringOutput); |
||
| 111 | |||
| 112 | $ds = DIRECTORY_SEPARATOR; |
||
| 113 | $errorMessage = 'Function call: dummy_deprecated_function1 (deprecated since 1.1) Remove it'; |
||
| 114 | |||
| 115 | $instance1Path = 'test_files/fake_elgg/' . $ds . 'engine' . $ds . 'lib' . $ds . 'foobar.php'; |
||
| 116 | $this->assertContains($instance1Path . "\n Line 8:\t" . $errorMessage, $stringOutput); |
||
| 117 | |||
| 118 | $instance2Path = 'test_files/fake_elgg/' . $ds . 'mod' . $ds . 'ugly_plugin' . $ds . 'classes' . $ds . 'ugly_plugin.php'; |
||
| 119 | $this->assertContains($instance2Path . "\n Line 9:\t" . $errorMessage, $stringOutput); |
||
| 120 | } |
||
| 121 | |||
| 122 | public function testAnalysisAllPluginsNoPrivate12() { |
||
| 123 | $config = new \CodeReview\Config(array(), array($this, 'getLatestVersion')); |
||
| 124 | $config->parseInput(array( |
||
| 125 | 'subpath' => '', |
||
| 126 | 'version' => '1.2', |
||
| 127 | 'include_disabled_plugins' => true, |
||
| 128 | 'find_deprecated_functions' => true, |
||
| 129 | 'find_private_functions' => false, |
||
| 130 | 'fix_problems' => false, |
||
| 131 | )); |
||
| 132 | |||
| 133 | $analyzer = new \CodeReview\Analyzer($config); |
||
| 134 | $analyzer->analyze(); |
||
| 135 | $stringOutput = $analyzer->outputReport(); |
||
| 136 | |||
| 137 | $this->assertContains("Subpath selected <strong>/</strong>", $stringOutput); |
||
| 138 | $this->assertContains("Max version: 1.2", $stringOutput); |
||
| 139 | $this->assertContains("Skipped inactive plugins: no", $stringOutput); |
||
| 140 | $this->assertContains("Search for deprecated functions usage: yes", $stringOutput); |
||
| 141 | $this->assertContains("Search for private functions usage: no", $stringOutput); |
||
| 142 | $this->assertContains("Attempt to fix problems: no", $stringOutput); |
||
| 143 | $this->assertContains("Found 3 problems in 3 files", $stringOutput); |
||
| 144 | $this->assertContains("Found 0 fixes in 3 files", $stringOutput); |
||
| 145 | $this->assertContains("Processed 13 files total", $stringOutput); |
||
| 146 | $this->assertNotContains("Time taken: ", $stringOutput); |
||
| 147 | |||
| 148 | $ds = DIRECTORY_SEPARATOR; |
||
| 149 | $errorMessage = 'Function call: dummy_deprecated_function1 (deprecated since 1.1) Remove it'; |
||
| 150 | |||
| 151 | $instance1Path = 'test_files/fake_elgg/' . $ds . 'engine' . $ds . 'lib' . $ds . 'foobar.php'; |
||
| 152 | $this->assertContains($instance1Path . "\n Line 8:\t" . $errorMessage, $stringOutput); |
||
| 153 | |||
| 154 | $instance2Path = 'test_files/fake_elgg/' . $ds . 'mod' . $ds . 'ugly_plugin' . $ds . 'classes' . $ds . 'ugly_plugin.php'; |
||
| 155 | $this->assertContains($instance2Path . "\n Line 9:\t" . $errorMessage, $stringOutput); |
||
| 156 | |||
| 157 | $instance3Path = 'test_files/fake_elgg/' . $ds . 'mod' . $ds . 'inactive_plugin' . $ds . 'start.php'; |
||
| 158 | $this->assertContains($instance3Path . "\n Line 5:\t" . $errorMessage, $stringOutput); |
||
| 159 | } |
||
| 160 | |||
| 161 | public function testAnalysisAllPluginsPrivate12() { |
||
| 162 | $config = new \CodeReview\Config(array(), array($this, 'getLatestVersion')); |
||
| 163 | $config->parseInput(array( |
||
| 164 | 'subpath' => '', |
||
| 165 | 'version' => '1.2', |
||
| 166 | 'include_disabled_plugins' => true, |
||
| 167 | 'find_deprecated_functions' => true, |
||
| 168 | 'find_private_functions' => true, |
||
| 169 | 'fix_problems' => false, |
||
| 170 | )); |
||
| 171 | |||
| 172 | $analyzer = new \CodeReview\Analyzer($config); |
||
| 173 | $analyzer->analyze(); |
||
| 174 | $stringOutput = $analyzer->outputReport(); |
||
| 175 | |||
| 176 | $this->assertContains("Subpath selected <strong>/</strong>", $stringOutput); |
||
| 177 | $this->assertContains("Max version: 1.2", $stringOutput); |
||
| 178 | $this->assertContains("Skipped inactive plugins: no", $stringOutput); |
||
| 179 | $this->assertContains("Search for deprecated functions usage: yes", $stringOutput); |
||
| 180 | $this->assertContains("Search for private functions usage: yes", $stringOutput); |
||
| 181 | $this->assertContains("Attempt to fix problems: no", $stringOutput); |
||
| 182 | $this->assertContains("Found 4 problems in 3 files", $stringOutput); |
||
| 183 | $this->assertContains("Found 0 fixes in 3 files", $stringOutput); |
||
| 184 | $this->assertContains("Processed 13 files total", $stringOutput); |
||
| 185 | $this->assertNotContains("Time taken: ", $stringOutput); |
||
| 186 | |||
| 187 | $ds = DIRECTORY_SEPARATOR; |
||
| 188 | $errorMessage1 = 'Function call: dummy_deprecated_function1 (deprecated since 1.1) Remove it'; |
||
| 189 | $errorMessage2 = 'Function call: foobar_private_api (use of function marked private is unsafe)'; |
||
| 190 | |||
| 191 | $instance1Path = 'test_files/fake_elgg/' . $ds . 'engine' . $ds . 'lib' . $ds . 'foobar.php'; |
||
| 192 | $this->assertContains($instance1Path . "\n Line 8:\t" . $errorMessage1, $stringOutput); |
||
| 193 | |||
| 194 | $instance2Path = 'test_files/fake_elgg/' . $ds . 'mod' . $ds . 'ugly_plugin' . $ds . 'classes' . $ds . 'ugly_plugin.php'; |
||
| 195 | $this->assertContains($instance2Path . "\n Line 9:\t" . $errorMessage1 . "\n Line 13:\t" . $errorMessage2, $stringOutput); |
||
| 196 | |||
| 197 | $instance3Path = 'test_files/fake_elgg/' . $ds . 'mod' . $ds . 'inactive_plugin' . $ds . 'start.php'; |
||
| 198 | $this->assertContains($instance3Path . "\n Line 5:\t" . $errorMessage1, $stringOutput); |
||
| 199 | } |
||
| 200 | |||
| 201 | public function testAnalysisAllPluginsPrivateSubpathEngine12() { |
||
| 202 | $config = new \CodeReview\Config(array(), array($this, 'getLatestVersion')); |
||
| 203 | $config->parseInput(array( |
||
| 204 | 'subpath' => 'engine', |
||
| 205 | 'version' => '1.2', |
||
| 206 | 'include_disabled_plugins' => true, |
||
| 207 | 'find_deprecated_functions' => true, |
||
| 208 | 'find_private_functions' => true, |
||
| 209 | 'fix_problems' => false, |
||
| 210 | )); |
||
| 211 | |||
| 212 | $analyzer = new \CodeReview\Analyzer($config); |
||
| 213 | $analyzer->analyze(); |
||
| 214 | $stringOutput = $analyzer->outputReport(); |
||
| 215 | |||
| 216 | $this->assertContains("Subpath selected <strong>engine/</strong>", $stringOutput); |
||
| 217 | $this->assertContains("Max version: 1.2", $stringOutput); |
||
| 218 | $this->assertContains("Skipped inactive plugins: no", $stringOutput); |
||
| 219 | $this->assertContains("Search for deprecated functions usage: yes", $stringOutput); |
||
| 220 | $this->assertContains("Search for private functions usage: yes", $stringOutput); |
||
| 221 | $this->assertContains("Attempt to fix problems: no", $stringOutput); |
||
| 222 | $this->assertContains("Found 1 problems in 1 files", $stringOutput); |
||
| 223 | $this->assertContains("Found 0 fixes in 1 files", $stringOutput); |
||
| 224 | $this->assertContains("Processed 8 files total", $stringOutput); |
||
| 225 | $this->assertNotContains("Time taken: ", $stringOutput); |
||
| 226 | |||
| 227 | $ds = DIRECTORY_SEPARATOR; |
||
| 228 | $errorMessage1 = 'Function call: dummy_deprecated_function1 (deprecated since 1.1) Remove it'; |
||
| 229 | |||
| 230 | $instance1Path = 'test_files/fake_elgg/' . 'engine' . $ds . 'lib' . $ds . 'foobar.php'; |
||
| 231 | $this->assertContains($instance1Path . "\n Line 8:\t" . $errorMessage1, $stringOutput); |
||
| 232 | } |
||
| 233 | |||
| 234 | public function testAnalysisAllPluginsPrivateSubpathInactive12() { |
||
| 235 | $config = new \CodeReview\Config(array(), array($this, 'getLatestVersion')); |
||
| 236 | $config->parseInput(array( |
||
| 237 | 'subpath' => 'mod/inactive_plugin/', |
||
| 238 | 'version' => '1.2', |
||
| 239 | 'include_disabled_plugins' => true, |
||
| 240 | 'find_deprecated_functions' => true, |
||
| 241 | 'find_private_functions' => true, |
||
| 242 | 'fix_problems' => false, |
||
| 243 | )); |
||
| 244 | |||
| 245 | $analyzer = new \CodeReview\Analyzer($config); |
||
| 246 | $analyzer->analyze(); |
||
| 247 | $stringOutput = $analyzer->outputReport(); |
||
| 248 | |||
| 249 | $this->assertContains("Subpath selected <strong>mod/inactive_plugin/</strong>", $stringOutput); |
||
| 250 | $this->assertContains("Max version: 1.2", $stringOutput); |
||
| 251 | $this->assertContains("Skipped inactive plugins: no", $stringOutput); |
||
| 252 | $this->assertContains("Search for deprecated functions usage: yes", $stringOutput); |
||
| 253 | $this->assertContains("Search for private functions usage: yes", $stringOutput); |
||
| 254 | $this->assertContains("Attempt to fix problems: no", $stringOutput); |
||
| 255 | $this->assertContains("Found 1 problems in 1 files", $stringOutput); |
||
| 256 | $this->assertContains("Found 0 fixes in 1 files", $stringOutput); |
||
| 257 | $this->assertContains("Processed 1 files total", $stringOutput); |
||
| 258 | $this->assertNotContains("Time taken: ", $stringOutput); |
||
| 259 | |||
| 260 | $ds = DIRECTORY_SEPARATOR; |
||
| 261 | $errorMessage1 = 'Function call: dummy_deprecated_function1 (deprecated since 1.1) Remove it'; |
||
| 262 | |||
| 263 | $instance3Path = 'test_files/fake_elgg/mod/inactive_plugin' . $ds . 'start.php'; |
||
| 264 | $this->assertContains($instance3Path . "\n Line 5:\t" . $errorMessage1, $stringOutput); |
||
| 265 | } |
||
| 266 | |||
| 267 | public function testAnalysisAllPluginsPrivateSubpathUgly12() { |
||
| 268 | $config = new \CodeReview\Config(array(), array($this, 'getLatestVersion')); |
||
| 269 | $config->parseInput(array( |
||
| 270 | 'subpath' => 'mod/ugly_plugin', |
||
| 271 | 'version' => '1.2', |
||
| 272 | 'include_disabled_plugins' => true, |
||
| 273 | 'find_deprecated_functions' => true, |
||
| 274 | 'find_private_functions' => true, |
||
| 275 | 'fix_problems' => false, |
||
| 276 | )); |
||
| 277 | |||
| 278 | $analyzer = new \CodeReview\Analyzer($config); |
||
| 279 | $analyzer->analyze(); |
||
| 280 | $stringOutput = $analyzer->outputReport(); |
||
| 281 | |||
| 282 | $this->assertContains("Subpath selected <strong>mod/ugly_plugin/</strong>", $stringOutput); |
||
| 283 | $this->assertContains("Max version: 1.2", $stringOutput); |
||
| 284 | $this->assertContains("Skipped inactive plugins: no", $stringOutput); |
||
| 285 | $this->assertContains("Search for deprecated functions usage: yes", $stringOutput); |
||
| 286 | $this->assertContains("Search for private functions usage: yes", $stringOutput); |
||
| 287 | $this->assertContains("Attempt to fix problems: no", $stringOutput); |
||
| 288 | $this->assertContains("Found 2 problems in 1 files", $stringOutput); |
||
| 289 | $this->assertContains("Found 0 fixes in 1 files", $stringOutput); |
||
| 290 | $this->assertContains("Processed 4 files total", $stringOutput); |
||
| 291 | $this->assertNotContains("Time taken: ", $stringOutput); |
||
| 292 | |||
| 293 | $ds = DIRECTORY_SEPARATOR; |
||
| 294 | $errorMessage1 = 'Function call: dummy_deprecated_function1 (deprecated since 1.1) Remove it'; |
||
| 295 | $errorMessage2 = 'Function call: foobar_private_api (use of function marked private is unsafe)'; |
||
| 296 | |||
| 297 | $instance2Path = 'test_files/fake_elgg/mod/ugly_plugin' . $ds . 'classes' . $ds . 'ugly_plugin.php'; |
||
| 298 | $this->assertContains($instance2Path . "\n Line 9:\t" . $errorMessage1 . "\n Line 13:\t" . $errorMessage2, $stringOutput); |
||
| 299 | } |
||
| 300 | |||
| 301 | public function testAnalysisAllPluginsPrivate11() { |
||
| 302 | $config = new \CodeReview\Config(array(), array($this, 'getLatestVersion')); |
||
| 303 | $config->parseInput(array( |
||
| 304 | 'subpath' => '', |
||
| 305 | 'version' => '1.1', |
||
| 306 | 'include_disabled_plugins' => true, |
||
| 307 | 'find_deprecated_functions' => true, |
||
| 308 | 'find_private_functions' => true, |
||
| 309 | 'fix_problems' => false, |
||
| 310 | )); |
||
| 311 | |||
| 312 | $analyzer = new \CodeReview\Analyzer($config); |
||
| 313 | $analyzer->analyze(); |
||
| 314 | $stringOutput = $analyzer->outputReport(); |
||
| 315 | |||
| 316 | $this->assertContains("Subpath selected <strong>/</strong>", $stringOutput); |
||
| 317 | $this->assertContains("Max version: 1.1", $stringOutput); |
||
| 318 | $this->assertContains("Skipped inactive plugins: no", $stringOutput); |
||
| 319 | $this->assertContains("Search for deprecated functions usage: yes", $stringOutput); |
||
| 320 | $this->assertContains("Search for private functions usage: yes", $stringOutput); |
||
| 321 | $this->assertContains("Attempt to fix problems: no", $stringOutput); |
||
| 322 | $this->assertContains("Found 1 problems in 1 files", $stringOutput); |
||
| 323 | $this->assertContains("Found 0 fixes in 1 files", $stringOutput); |
||
| 324 | $this->assertContains("Processed 13 files total", $stringOutput); |
||
| 325 | $this->assertNotContains("Time taken: ", $stringOutput); |
||
| 326 | |||
| 327 | $ds = DIRECTORY_SEPARATOR; |
||
| 328 | $errorMessage2 = 'Function call: foobar_private_api (use of function marked private is unsafe)'; |
||
| 329 | |||
| 330 | $instance2Path = 'test_files/fake_elgg/' . $ds . 'mod' . $ds . 'ugly_plugin' . $ds . 'classes' . $ds . 'ugly_plugin.php'; |
||
| 331 | $this->assertContains($instance2Path . "\n Line 13:\t" . $errorMessage2, $stringOutput); |
||
| 332 | } |
||
| 333 | } |
||
| 334 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.