Skip to content

Commit 5a3770e

Browse files
authored
Merge pull request #250 from rodrigoprimo/test-coverage-uselessoverriding-method
Generic/UselessOverridingMethod: improve code coverage
2 parents 1d256d1 + d179487 commit 5a3770e

7 files changed

+130
-30
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
class FooBar {
4+
public function __construct($a, $b) {
5+
parent::__construct($a, $b);
6+
}
7+
}
8+
9+
class BarFoo {
10+
public function __construct($a, $b) {
11+
parent::__construct($a, 'XML', $b);
12+
}
13+
}
14+
15+
class Foo {
16+
public function export($a, $b = null) {
17+
return parent::export($a, $b);
18+
}
19+
}
20+
21+
class Bar {
22+
public function export($a, $b = null) {
23+
return parent::export($a);
24+
}
25+
26+
public function ignoreNoParent($a, $b) {
27+
return $a + $b;
28+
}
29+
30+
public function differentParentMethod($a, $b) {
31+
return parent::anotherMethod($a, $b);
32+
}
33+
34+
public function methodCallWithExpression($a, $b) {
35+
return parent::methodCallWithExpression(($a + $b), ($b));
36+
}
37+
38+
public function uselessMethodCallWithExpression($a, $b) {
39+
return parent::uselessMethodCallWithExpression(($a), ($b));
40+
}
41+
42+
public function contentAfterCallingParent() {
43+
parent::contentAfterCallingParent();
44+
45+
return 1;
46+
}
47+
48+
public function ignoreNoParentVoidMethod($a, $b) {
49+
$c = $a + $b;
50+
}
51+
52+
public function modifiesParentReturnValue($a, $b) {
53+
return parent::modifiesParentReturnValue($a, $b) + $b;
54+
}
55+
56+
public function uselessMethodCallTrailingComma($a) {
57+
return parent::uselessMethodCallTrailingComma($a,);
58+
}
59+
60+
public function differentParameterOrder($a, $b) {
61+
return parent::differentParameterOrder($b, $a);
62+
}
63+
64+
public function sameNumberDifferentParameters($a, $b) {
65+
return parent::sameNumberDifferentParameters($this->prop[$a], $this->{$b});
66+
}
67+
}
68+
69+
abstract class AbstractFoo {
70+
abstract public function sniffShouldBailEarly();
71+
}
72+
73+
interface InterfaceFoo {
74+
public function sniffShouldBailEarly();
75+
}
76+
77+
trait TraitFoo {
78+
abstract public function sniffShouldBailEarly();
79+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
// Intentional parse error (missing opening bracket). Testing that the sniff is *not* triggered
4+
// in this case.
5+
6+
class FooBar {
7+
public function __construct()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
// Intentional parse error (missing double colon after parent keyword). Testing that the sniff is *not* triggered
4+
// in this case.
5+
6+
class FooBar {
7+
public function __construct() {
8+
parent
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
// Intentional parse error (missing parent method opening parenthesis).
4+
// Testing that the sniff is *not* triggered in this case.
5+
6+
class FooBar {
7+
public function __construct() {
8+
parent::__construct
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
// Intentional parse error (missing semicolon).
4+
// Testing that the sniff is *not* triggered in this case.
5+
6+
class FooBar {
7+
public function __construct() {
8+
parent::__construct()
9+
}
10+
}

src/Standards/Generic/Tests/CodeAnalysis/UselessOverridingMethodUnitTest.inc

-25
This file was deleted.

src/Standards/Generic/Tests/CodeAnalysis/UselessOverridingMethodUnitTest.php

+14-5
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,23 @@ public function getErrorList()
4141
* The key of the array should represent the line number and the value
4242
* should represent the number of warnings that should occur on that line.
4343
*
44+
* @param string $testFile The name of the file being tested.
45+
*
4446
* @return array<int, int>
4547
*/
46-
public function getWarningList()
48+
public function getWarningList($testFile='')
4749
{
48-
return [
49-
4 => 1,
50-
16 => 1,
51-
];
50+
switch ($testFile) {
51+
case 'UselessOverridingMethodUnitTest.1.inc':
52+
return [
53+
4 => 1,
54+
16 => 1,
55+
38 => 1,
56+
56 => 1,
57+
];
58+
default:
59+
return [];
60+
}
5261

5362
}//end getWarningList()
5463

0 commit comments

Comments
 (0)