| 1 |
87
|
mapi |
<?php |
|
| 2 |
↓
|
mapi |
/** |
|
| 3 |
↓
|
mapi |
* This file is part of PHP_PMD. |
|
| 4 |
↓
|
mapi |
* |
|
| 5 |
↓
|
mapi |
* PHP Version 5 |
|
| 6 |
↓
|
mapi |
* |
|
| 7 |
174
|
mapi |
* Copyright (c) 2009-2010, Manuel Pichler <mapi@phpmd.org>. |
|
| 8 |
87
|
mapi |
* All rights reserved. |
|
| 9 |
↓
|
mapi |
* |
|
| 10 |
↓
|
mapi |
* Redistribution and use in source and binary forms, with or without |
|
| 11 |
↓
|
mapi |
* modification, are permitted provided that the following conditions |
|
| 12 |
↓
|
mapi |
* are met: |
|
| 13 |
↓
|
mapi |
* |
|
| 14 |
↓
|
mapi |
* * Redistributions of source code must retain the above copyright |
|
| 15 |
↓
|
mapi |
* notice, this list of conditions and the following disclaimer. |
|
| 16 |
↓
|
mapi |
* |
|
| 17 |
↓
|
mapi |
* * Redistributions in binary form must reproduce the above copyright |
|
| 18 |
↓
|
mapi |
* notice, this list of conditions and the following disclaimer in |
|
| 19 |
↓
|
mapi |
* the documentation and/or other materials provided with the |
|
| 20 |
↓
|
mapi |
* distribution. |
|
| 21 |
↓
|
mapi |
* |
|
| 22 |
↓
|
mapi |
* * Neither the name of Manuel Pichler nor the names of his |
|
| 23 |
↓
|
mapi |
* contributors may be used to endorse or promote products derived |
|
| 24 |
↓
|
mapi |
* from this software without specific prior written permission. |
|
| 25 |
↓
|
mapi |
* |
|
| 26 |
↓
|
mapi |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
| 27 |
↓
|
mapi |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
| 28 |
↓
|
mapi |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
| 29 |
↓
|
mapi |
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
| 30 |
↓
|
mapi |
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
|
| 31 |
↓
|
mapi |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
| 32 |
↓
|
mapi |
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
| 33 |
↓
|
mapi |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
| 34 |
↓
|
mapi |
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
| 35 |
↓
|
mapi |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
| 36 |
↓
|
mapi |
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
| 37 |
↓
|
mapi |
* POSSIBILITY OF SUCH DAMAGE. |
|
| 38 |
↓
|
mapi |
* |
|
| 39 |
↓
|
mapi |
* @category PHP |
|
| 40 |
↓
|
mapi |
* @package PHP_PMD |
|
| 41 |
88
|
mapi |
* @subpackage Rule_Design |
|
| 42 |
174
|
mapi |
* @author Manuel Pichler <mapi@phpmd.org> |
|
| 43 |
150
|
mapi |
* @copyright 2009-2010 Manuel Pichler. All rights reserved. |
|
| 44 |
87
|
mapi |
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
| 45 |
↓
|
mapi |
* @version SVN: $Id$ |
|
| 46 |
174
|
mapi |
* @link http://phpmd.org |
|
| 47 |
87
|
mapi |
*/ |
|
| 48 |
↓
|
mapi |
|
|
| 49 |
↓
|
mapi |
require_once dirname(__FILE__) . '/../../AbstractTest.php'; |
|
| 50 |
↓
|
mapi |
|
|
| 51 |
↓
|
mapi |
require_once 'PHP/PMD/Rule/Design/LongParameterList.php'; |
|
| 52 |
↓
|
mapi |
|
|
| 53 |
↓
|
mapi |
/** |
|
| 54 |
↓
|
mapi |
* Test case for the excessive long parameter list rule. |
|
| 55 |
↓
|
mapi |
* |
|
| 56 |
↓
|
mapi |
* @category PHP |
|
| 57 |
↓
|
mapi |
* @package PHP_PMD |
|
| 58 |
88
|
mapi |
* @subpackage Rule_Design |
|
| 59 |
174
|
mapi |
* @author Manuel Pichler <mapi@phpmd.org> |
|
| 60 |
150
|
mapi |
* @copyright 2009-2010 Manuel Pichler. All rights reserved. |
|
| 61 |
87
|
mapi |
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
| 62 |
↓
|
mapi |
* @version Release: @package_version@ |
|
| 63 |
174
|
mapi |
* @link http://phpmd.org |
|
| 64 |
87
|
mapi |
*/ |
|
| 65 |
↓
|
mapi |
class PHP_PMD_Rule_Design_LongParameterListTest extends PHP_PMD_AbstractTest |
|
| 66 |
↓
|
mapi |
{ |
|
| 67 |
↓
|
mapi |
/** |
|
| 68 |
↓
|
mapi |
* testApplyIgnoresMethodsWithLessParametersThanMinimum |
|
| 69 |
↓
|
mapi |
* |
|
| 70 |
↓
|
mapi |
* @return void |
|
| 71 |
↓
|
mapi |
* @covers PHP_PMD_Rule_Design_LongParameterList |
|
| 72 |
↓
|
mapi |
* @group phpmd |
|
| 73 |
127
|
mapi |
* @group phpmd::rule |
|
| 74 |
↓
|
mapi |
* @group phpmd::rule::design |
|
| 75 |
87
|
mapi |
* @group unittest |
|
| 76 |
↓
|
mapi |
*/ |
|
| 77 |
↓
|
mapi |
public function testApplyIgnoresMethodsWithLessParametersThanMinimum() |
|
| 78 |
↓
|
mapi |
{ |
|
| 79 |
↓
|
mapi |
$rule = new PHP_PMD_Rule_Design_LongParameterList(); |
|
| 80 |
↓
|
mapi |
$rule->setReport($this->getReportMock(0)); |
|
| 81 |
↓
|
mapi |
$rule->addProperty('minimum', '4'); |
|
| 82 |
↓
|
mapi |
$rule->apply($this->_createMethod(3)); |
|
| 83 |
↓
|
mapi |
} |
|
| 84 |
↓
|
mapi |
|
|
| 85 |
↓
|
mapi |
/** |
|
| 86 |
↓
|
mapi |
* testApplyReportsMethodsWithIdenticalParametersAndMinimum |
|
| 87 |
↓
|
mapi |
* |
|
| 88 |
↓
|
mapi |
* @return void |
|
| 89 |
↓
|
mapi |
* @covers PHP_PMD_Rule_Design_LongParameterList |
|
| 90 |
↓
|
mapi |
* @group phpmd |
|
| 91 |
127
|
mapi |
* @group phpmd::rule |
|
| 92 |
↓
|
mapi |
* @group phpmd::rule::design |
|
| 93 |
87
|
mapi |
* @group unittest |
|
| 94 |
↓
|
mapi |
*/ |
|
| 95 |
↓
|
mapi |
public function testApplyReportsMethodsWithIdenticalParametersAndMinimum() |
|
| 96 |
↓
|
mapi |
{ |
|
| 97 |
↓
|
mapi |
$rule = new PHP_PMD_Rule_Design_LongParameterList(); |
|
| 98 |
↓
|
mapi |
$rule->setReport($this->getReportMock(1)); |
|
| 99 |
↓
|
mapi |
$rule->addProperty('minimum', '3'); |
|
| 100 |
↓
|
mapi |
$rule->apply($this->_createMethod(3)); |
|
| 101 |
↓
|
mapi |
} |
|
| 102 |
↓
|
mapi |
|
|
| 103 |
↓
|
mapi |
/** |
|
| 104 |
↓
|
mapi |
* testApplyReportsMethodsWithMoreParametersThanMinimum |
|
| 105 |
↓
|
mapi |
* |
|
| 106 |
↓
|
mapi |
* @return void |
|
| 107 |
↓
|
mapi |
* @covers PHP_PMD_Rule_Design_LongParameterList |
|
| 108 |
↓
|
mapi |
* @group phpmd |
|
| 109 |
127
|
mapi |
* @group phpmd::rule |
|
| 110 |
↓
|
mapi |
* @group phpmd::rule::design |
|
| 111 |
87
|
mapi |
* @group unittest |
|
| 112 |
↓
|
mapi |
*/ |
|
| 113 |
↓
|
mapi |
public function testApplyReportsMethodsWithMoreParametersThanMinimum() |
|
| 114 |
↓
|
mapi |
{ |
|
| 115 |
↓
|
mapi |
$rule = new PHP_PMD_Rule_Design_LongParameterList(); |
|
| 116 |
↓
|
mapi |
$rule->setReport($this->getReportMock(1)); |
|
| 117 |
↓
|
mapi |
$rule->addProperty('minimum', '3'); |
|
| 118 |
↓
|
mapi |
$rule->apply($this->_createMethod(42)); |
|
| 119 |
↓
|
mapi |
} |
|
| 120 |
↓
|
mapi |
|
|
| 121 |
↓
|
mapi |
/** |
|
| 122 |
↓
|
mapi |
* testApplyIgnoresFunctionsWithLessParametersThanMinimum |
|
| 123 |
↓
|
mapi |
* |
|
| 124 |
↓
|
mapi |
* @return void |
|
| 125 |
↓
|
mapi |
* @covers PHP_PMD_Rule_Design_LongParameterList |
|
| 126 |
↓
|
mapi |
* @group phpmd |
|
| 127 |
127
|
mapi |
* @group phpmd::rule |
|
| 128 |
↓
|
mapi |
* @group phpmd::rule::design |
|
| 129 |
87
|
mapi |
* @group unittest |
|
| 130 |
↓
|
mapi |
*/ |
|
| 131 |
↓
|
mapi |
public function testApplyIgnoresFunctionsWithLessParametersThanMinimum() |
|
| 132 |
↓
|
mapi |
{ |
|
| 133 |
↓
|
mapi |
$rule = new PHP_PMD_Rule_Design_LongParameterList(); |
|
| 134 |
↓
|
mapi |
$rule->setReport($this->getReportMock(0)); |
|
| 135 |
↓
|
mapi |
$rule->addProperty('minimum', '4'); |
|
| 136 |
↓
|
mapi |
$rule->apply($this->_createFunction(3)); |
|
| 137 |
↓
|
mapi |
} |
|
| 138 |
↓
|
mapi |
|
|
| 139 |
↓
|
mapi |
/** |
|
| 140 |
↓
|
mapi |
* testApplyReportsFunctionsWithIdenticalParametersAndMinimum |
|
| 141 |
↓
|
mapi |
* |
|
| 142 |
↓
|
mapi |
* @return void |
|
| 143 |
↓
|
mapi |
* @covers PHP_PMD_Rule_Design_LongParameterList |
|
| 144 |
↓
|
mapi |
* @group phpmd |
|
| 145 |
127
|
mapi |
* @group phpmd::rule |
|
| 146 |
↓
|
mapi |
* @group phpmd::rule::design |
|
| 147 |
87
|
mapi |
* @group unittest |
|
| 148 |
↓
|
mapi |
*/ |
|
| 149 |
↓
|
mapi |
public function testApplyReportsFunctionsWithIdenticalParametersAndMinimum() |
|
| 150 |
↓
|
mapi |
{ |
|
| 151 |
↓
|
mapi |
$rule = new PHP_PMD_Rule_Design_LongParameterList(); |
|
| 152 |
↓
|
mapi |
$rule->setReport($this->getReportMock(1)); |
|
| 153 |
↓
|
mapi |
$rule->addProperty('minimum', '3'); |
|
| 154 |
↓
|
mapi |
$rule->apply($this->_createFunction(3)); |
|
| 155 |
↓
|
mapi |
} |
|
| 156 |
↓
|
mapi |
|
|
| 157 |
↓
|
mapi |
/** |
|
| 158 |
↓
|
mapi |
* testApplyReportsFunctionsWithMoreParametersThanMinimum |
|
| 159 |
↓
|
mapi |
* |
|
| 160 |
↓
|
mapi |
* @return void |
|
| 161 |
↓
|
mapi |
* @covers PHP_PMD_Rule_Design_LongParameterList |
|
| 162 |
↓
|
mapi |
* @group phpmd |
|
| 163 |
127
|
mapi |
* @group phpmd::rule |
|
| 164 |
↓
|
mapi |
* @group phpmd::rule::design |
|
| 165 |
87
|
mapi |
* @group unittest |
|
| 166 |
↓
|
mapi |
*/ |
|
| 167 |
↓
|
mapi |
public function testApplyReportsFunctionsWithMoreParametersThanMinimum() |
|
| 168 |
↓
|
mapi |
{ |
|
| 169 |
↓
|
mapi |
$rule = new PHP_PMD_Rule_Design_LongParameterList(); |
|
| 170 |
↓
|
mapi |
$rule->setReport($this->getReportMock(1)); |
|
| 171 |
↓
|
mapi |
$rule->addProperty('minimum', '3'); |
|
| 172 |
↓
|
mapi |
$rule->apply($this->_createFunction(42)); |
|
| 173 |
↓
|
mapi |
} |
|
| 174 |
↓
|
mapi |
|
|
| 175 |
↓
|
mapi |
/** |
|
| 176 |
↓
|
mapi |
* Returns a mocked method instance. |
|
| 177 |
↓
|
mapi |
* |
|
| 178 |
↓
|
mapi |
* @param integer $parameterCount Number of method parameters. |
|
| 179 |
↓
|
mapi |
* |
|
| 180 |
200
|
mapi |
* @return PHP_PMD_Node_Method |
|
| 181 |
87
|
mapi |
*/ |
|
| 182 |
↓
|
mapi |
private function _createMethod($parameterCount) |
|
| 183 |
↓
|
mapi |
{ |
|
| 184 |
↓
|
mapi |
return $this->_initFunctionOrMethod($this->getMethodMock(), $parameterCount); |
|
| 185 |
↓
|
mapi |
} |
|
| 186 |
↓
|
mapi |
|
|
| 187 |
↓
|
mapi |
/** |
|
| 188 |
↓
|
mapi |
* Creates a mocked function node instance. |
|
| 189 |
↓
|
mapi |
* |
|
| 190 |
↓
|
mapi |
* @param integer $parameterCount Number of function parameters. |
|
| 191 |
↓
|
mapi |
* |
|
| 192 |
200
|
mapi |
* @return PHP_PMD_Node_Function |
|
| 193 |
87
|
mapi |
*/ |
|
| 194 |
↓
|
mapi |
private function _createFunction($parameterCount) |
|
| 195 |
↓
|
mapi |
{ |
|
| 196 |
173
|
mapi |
return $this->_initFunctionOrMethod($this->createFunctionMock(), $parameterCount); |
|
| 197 |
87
|
mapi |
} |
|
| 198 |
↓
|
mapi |
|
|
| 199 |
↓
|
mapi |
/** |
|
| 200 |
↓
|
mapi |
* Initializes the getParameterCount() method of the given callable. |
|
| 201 |
↓
|
mapi |
* |
|
| 202 |
200
|
mapi |
* @param PHP_PMD_Node_Function|PHP_PMD_Node_Method $mock Mocked callable. |
|
| 203 |
87
|
mapi |
* @param integer $parameterCount Number of parameters. |
|
| 204 |
↓
|
mapi |
* |
|
| 205 |
200
|
mapi |
* @return PHP_PMD_Node_Function|PHP_PMD_Node_Method |
|
| 206 |
87
|
mapi |
*/ |
|
| 207 |
↓
|
mapi |
private function _initFunctionOrMethod($mock, $parameterCount) |
|
| 208 |
↓
|
mapi |
{ |
|
| 209 |
↓
|
mapi |
$mock->expects($this->once()) |
|
| 210 |
↓
|
mapi |
->method('getParameterCount') |
|
| 211 |
↓
|
mapi |
->will($this->returnValue($parameterCount)); |
|
| 212 |
↓
|
mapi |
|
|
| 213 |
↓
|
mapi |
return $mock; |
|
| 214 |
↓
|
mapi |
} |
|
| 215 |
↓
|
mapi |
} |
|