Arbit - project tracking

PHP Depend

History

Diff

1111 1112 /tests/PHP/Depend/Bugs/AllTests.php
79 79 require_once dirname(__FILE__) . '/ComplexStringParsingBug114Test.php';
80 80 require_once dirname(__FILE__) . '/SummaryReportContainsClassesWithoutSourceFileBug115Test.php';
81 81 require_once dirname(__FILE__) . '/KeywordFunctionNameResultsInExceptionBug116Test.php';
82 +require_once dirname(__FILE__) . '/MethodsDeclaredAbstractAreCountedAsOverwrittenBug118Test.php';
82 83
83 84 /**
84 85 * Test suite for bugs meta package.
138 139 $suite->addTestSuite('PHP_Depend_Bugs_ComplexStringParsingBug114Test');
139 140 $suite->addTestSuite('PHP_Depend_Bugs_SummaryReportContainsClassesWithoutSourceFileBug115Test');
140 141 $suite->addTestSuite('PHP_Depend_Bugs_KeywordFunctionNameResultsInExceptionBug116Test');
142 + $suite->addTestSuite('PHP_Depend_Bugs_MethodsDeclaredAbstractAreCountedAsOverwrittenBug118Test');
141 143
142 144 return $suite;
143 145 }
1111 1112 /tests/PHP/Depend/Bugs/MethodsDeclaredAbstractAreCountedAsOverwrittenBug118Test.php
2 +<?php
3 +/**
4 + * This file is part of PHP_Depend.
5 + *
6 + * PHP Version 5
7 + *
8 + * Copyright (c) 2008-2010, Manuel Pichler <mapi@pdepend.org>.
9 + * All rights reserved.
10 + *
11 + * Redistribution and use in source and binary forms, with or without
12 + * modification, are permitted provided that the following conditions
13 + * are met:
14 + *
15 + * * Redistributions of source code must retain the above copyright
16 + * notice, this list of conditions and the following disclaimer.
17 + *
18 + * * Redistributions in binary form must reproduce the above copyright
19 + * notice, this list of conditions and the following disclaimer in
20 + * the documentation and/or other materials provided with the
21 + * distribution.
22 + *
23 + * * Neither the name of Manuel Pichler nor the names of his
24 + * contributors may be used to endorse or promote products derived
25 + * from this software without specific prior written permission.
26 + *
27 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31 + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
37 + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 + * POSSIBILITY OF SUCH DAMAGE.
39 + *
40 + * @category PHP
41 + * @package PHP_Depend
42 + * @subpackage Bugs
43 + * @author Manuel Pichler <mapi@pdepend.org>
44 + * @copyright 2008-2010 Manuel Pichler. All rights reserved.
45 + * @license http://www.opensource.org/licenses/bsd-license.php BSD License
46 + * @version SVN: $Id$
47 + * @link http://www.pdepend.org/
48 + */
49 +
50 +require_once dirname(__FILE__) . '/AbstractTest.php';
51 +
52 +/**
53 + * Test case for bug #118
54 + *
55 + * @category PHP
56 + * @package PHP_Depend
57 + * @subpackage Bugs
58 + * @author Manuel Pichler <mapi@pdepend.org>
59 + * @copyright 2008-2010 Manuel Pichler. All rights reserved.
60 + * @license http://www.opensource.org/licenses/bsd-license.php BSD License
61 + * @version Release: @package_version@
62 + * @link http://www.pdepend.org/
63 + */
64 +class PHP_Depend_Bugs_MethodsDeclaredAbstractAreCountedAsOverwrittenBug118Test
65 + extends PHP_Depend_Bugs_AbstractTest
66 +{
67 + /**
68 + * testAnalyzerNotCountsImplementedAbstractMethodsAsOverwritten
69 + *
70 + * @return void
71 + * @covers stdClass
72 + * @group pdepend
73 + * @group pdepend::bugs
74 + * @group regressiontest
75 + */
76 + public function testAnalyzerNotCountsImplementedAbstractMethodsAsOverwritten()
77 + {
78 + $packages = self::parseTestCaseSource(__METHOD__);
79 + $class = $packages->current()->getClasses()->current();
80 +
81 + $analyzer = new PHP_Depend_Metrics_Inheritance_Analyzer();
82 + $analyzer->analyze($packages);
83 +
84 + $metrics = $analyzer->getNodeMetrics($class);
85 + $this->assertEquals(1, $metrics['noom']);
86 + }
87 +
88 + /**
89 + * testAnalyzerNotCountsImplementedInterfaceMethodsAsOverwritten
90 + *
91 + * @return void
92 + * @covers stdClass
93 + * @group pdepend
94 + * @group pdepend::bugs
95 + * @group regressiontest
96 + */
97 + public function testAnalyzerNotCountsImplementedInterfaceMethodsAsOverwritten()
98 + {
99 + $packages = self::parseTestCaseSource(__METHOD__);
100 + $class = $packages->current()->getClasses()->current();
101 +
102 + $analyzer = new PHP_Depend_Metrics_Inheritance_Analyzer();
103 + $analyzer->analyze($packages);
104 +
105 + $metrics = $analyzer->getNodeMetrics($class);
106 + $this->assertEquals(1, $metrics['noom']);
107 + }
108 +}
1111 1112 /tests/PHP/Depend/_code/bugs/118/testAnalyzerNotCountsImplementedAbstractMethodsAsOverwritten.php
2 +<?php
3 +/**
4 + * @package foo
5 + */
6 +class testAnalyzerNotCountsImplementedAbstractMethodsAsOverwritten
7 + extends testAnalyzerNotCountsImplementedAbstractMethodsAsOverwrittenParent
8 +{
9 + public function foo() {}
10 + public function bar() {}
11 +}
12 +
13 +/**
14 + * @package foo
15 + */
16 +abstract class testAnalyzerNotCountsImplementedAbstractMethodsAsOverwrittenParent
17 +{
18 + public abstract function foo();
19 + public function bar() {}
20 +}
1111 1112 /tests/PHP/Depend/_code/bugs/118/testAnalyzerNotCountsImplementedInterfaceMethodsAsOverwritten.php
2 +<?php
3 +class testAnalyzerNotCountsImplementedInterfaceMethodsAsOverwritten
4 + extends testAnalyzerNotCountsImplementedInterfaceMethodsAsOverwrittenParent
5 +{
6 + public function foo() {}
7 + public function bar() {}
8 + protected function baz() {}
9 +}
10 +
11 +abstract class testAnalyzerNotCountsImplementedInterfaceMethodsAsOverwrittenParent
12 + implements testAnalyzerNotCountsImplementedInterfaceMethodsAsOverwrittenInterface
13 +{
14 + protected function baz() {}
15 +}
16 +
17 +interface testAnalyzerNotCountsImplementedInterfaceMethodsAsOverwrittenInterface
18 +{
19 + public function foo();
20 + function bar();
21 +}
1111 1112 /PHP/Depend/Metrics/Inheritance/Analyzer.php
311 311
312 312 $parentMethodNames = array();
313 313 foreach ($parentClass->getAllMethods() as $method) {
314 - $parentMethodNames[$method->getName()] = true;
314 + $parentMethodNames[$method->getName()] = $method->isAbstract();
315 315 }
316 316
317 317 $numberOfAddedMethods = 0;
323 323 }
324 324
325 325 if (isset($parentMethodNames[$method->getName()])) {
326 - ++$numberOfOverwrittenMethods;
326 + if (!$parentMethodNames[$method->getName()]) {
327 + ++$numberOfOverwrittenMethods;
328 + }
327 329 } else {
328 330 ++$numberOfAddedMethods;
329 331 }