| 1 |
41
|
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 |
41
|
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 |
41
|
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 |
41
|
mapi |
*/ |
|
| 48 |
↓
|
mapi |
|
|
| 49 |
↓
|
mapi |
require_once dirname(__FILE__) . '/../../AbstractTest.php'; |
|
| 50 |
↓
|
mapi |
|
|
| 51 |
48
|
mapi |
require_once 'PHP/PMD/Rule/Design/LongClass.php'; |
|
| 52 |
↓
|
mapi |
|
|
| 53 |
41
|
mapi |
/** |
|
| 54 |
↓
|
mapi |
* Test case for the excessive long class 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 |
41
|
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 |
41
|
mapi |
*/ |
|
| 65 |
↓
|
mapi |
class PHP_PMD_Rule_Design_LongClassTest extends PHP_PMD_AbstractTest |
|
| 66 |
↓
|
mapi |
{ |
|
| 67 |
48
|
mapi |
/** |
|
| 68 |
↓
|
mapi |
* Tests that the rule applies for a value greater than the configured |
|
| 69 |
↓
|
mapi |
* threshold. |
|
| 70 |
↓
|
mapi |
* |
|
| 71 |
↓
|
mapi |
* @return void |
|
| 72 |
200
|
mapi |
* @covers PHP_PMD_Rule_Design_LongClass |
|
| 73 |
127
|
mapi |
* @group phpmd |
|
| 74 |
↓
|
mapi |
* @group phpmd::rule |
|
| 75 |
↓
|
mapi |
* @group phpmd::rule::design |
|
| 76 |
↓
|
mapi |
* @group unittest |
|
| 77 |
48
|
mapi |
*/ |
|
| 78 |
↓
|
mapi |
public function testRuleAppliesForValueGreaterThanThreshold() |
|
| 79 |
↓
|
mapi |
{ |
|
| 80 |
↓
|
mapi |
$class = $this->getClassMock('loc', 42); |
|
| 81 |
↓
|
mapi |
$report = $this->getReportMock(1); |
|
| 82 |
↓
|
mapi |
|
|
| 83 |
↓
|
mapi |
$rule = new PHP_PMD_Rule_Design_LongClass(); |
|
| 84 |
↓
|
mapi |
$rule->setReport($report); |
|
| 85 |
↓
|
mapi |
$rule->addProperty('minimum', '41'); |
|
| 86 |
↓
|
mapi |
$rule->apply($class); |
|
| 87 |
↓
|
mapi |
} |
|
| 88 |
↓
|
mapi |
|
|
| 89 |
↓
|
mapi |
/** |
|
| 90 |
↓
|
mapi |
* Test that the rule applies for a value that is equal with the configured |
|
| 91 |
↓
|
mapi |
* threshold. |
|
| 92 |
↓
|
mapi |
* |
|
| 93 |
↓
|
mapi |
* @return void |
|
| 94 |
200
|
mapi |
* @covers PHP_PMD_Rule_Design_LongClass |
|
| 95 |
127
|
mapi |
* @group phpmd |
|
| 96 |
↓
|
mapi |
* @group phpmd::rule |
|
| 97 |
↓
|
mapi |
* @group phpmd::rule::design |
|
| 98 |
↓
|
mapi |
* @group unittest |
|
| 99 |
48
|
mapi |
*/ |
|
| 100 |
↓
|
mapi |
public function testRuleAppliesForValueEqualToThreshold() |
|
| 101 |
↓
|
mapi |
{ |
|
| 102 |
↓
|
mapi |
$class = $this->getClassMock('loc', 42); |
|
| 103 |
↓
|
mapi |
$report = $this->getReportMock(1); |
|
| 104 |
↓
|
mapi |
|
|
| 105 |
↓
|
mapi |
$rule = new PHP_PMD_Rule_Design_LongClass(); |
|
| 106 |
↓
|
mapi |
$rule->setReport($report); |
|
| 107 |
↓
|
mapi |
$rule->addProperty('minimum', '42'); |
|
| 108 |
↓
|
mapi |
$rule->apply($class); |
|
| 109 |
↓
|
mapi |
} |
|
| 110 |
↓
|
mapi |
|
|
| 111 |
↓
|
mapi |
/** |
|
| 112 |
↓
|
mapi |
* Tests that the rule does not apply when the value is at least one lower |
|
| 113 |
↓
|
mapi |
* than the threshold. |
|
| 114 |
↓
|
mapi |
* |
|
| 115 |
↓
|
mapi |
* @return void |
|
| 116 |
200
|
mapi |
* @covers PHP_PMD_Rule_Design_LongClass |
|
| 117 |
127
|
mapi |
* @group phpmd |
|
| 118 |
↓
|
mapi |
* @group phpmd::rule |
|
| 119 |
↓
|
mapi |
* @group phpmd::rule::design |
|
| 120 |
↓
|
mapi |
* @group unittest |
|
| 121 |
48
|
mapi |
*/ |
|
| 122 |
↓
|
mapi |
public function testRuleDoesNotApplyForValueLowerThanThreshold() |
|
| 123 |
↓
|
mapi |
{ |
|
| 124 |
↓
|
mapi |
$class = $this->getClassMock('loc', 22); |
|
| 125 |
↓
|
mapi |
$report = $this->getReportMock(0); |
|
| 126 |
↓
|
mapi |
|
|
| 127 |
↓
|
mapi |
$rule = new PHP_PMD_Rule_Design_LongClass(); |
|
| 128 |
↓
|
mapi |
$rule->setReport($report); |
|
| 129 |
↓
|
mapi |
$rule->addProperty('minimum', '23'); |
|
| 130 |
↓
|
mapi |
$rule->apply($class); |
|
| 131 |
↓
|
mapi |
} |
|
| 132 |
79
|
mapi |
} |
|