Skip to content

Commit

Permalink
Merge pull request #250 from rodrigoprimo/test-coverage-uselessoverri…
Browse files Browse the repository at this point in the history
…ding-method

Generic/UselessOverridingMethod: improve code coverage
  • Loading branch information
jrfnl authored Feb 24, 2024
2 parents 1d256d1 + d179487 commit 5a3770e
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

class FooBar {
public function __construct($a, $b) {
parent::__construct($a, $b);
}
}

class BarFoo {
public function __construct($a, $b) {
parent::__construct($a, 'XML', $b);
}
}

class Foo {
public function export($a, $b = null) {
return parent::export($a, $b);
}
}

class Bar {
public function export($a, $b = null) {
return parent::export($a);
}

public function ignoreNoParent($a, $b) {
return $a + $b;
}

public function differentParentMethod($a, $b) {
return parent::anotherMethod($a, $b);
}

public function methodCallWithExpression($a, $b) {
return parent::methodCallWithExpression(($a + $b), ($b));
}

public function uselessMethodCallWithExpression($a, $b) {
return parent::uselessMethodCallWithExpression(($a), ($b));
}

public function contentAfterCallingParent() {
parent::contentAfterCallingParent();

return 1;
}

public function ignoreNoParentVoidMethod($a, $b) {
$c = $a + $b;
}

public function modifiesParentReturnValue($a, $b) {
return parent::modifiesParentReturnValue($a, $b) + $b;
}

public function uselessMethodCallTrailingComma($a) {
return parent::uselessMethodCallTrailingComma($a,);
}

public function differentParameterOrder($a, $b) {
return parent::differentParameterOrder($b, $a);
}

public function sameNumberDifferentParameters($a, $b) {
return parent::sameNumberDifferentParameters($this->prop[$a], $this->{$b});
}
}

abstract class AbstractFoo {
abstract public function sniffShouldBailEarly();
}

interface InterfaceFoo {
public function sniffShouldBailEarly();
}

trait TraitFoo {
abstract public function sniffShouldBailEarly();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// Intentional parse error (missing opening bracket). Testing that the sniff is *not* triggered
// in this case.

class FooBar {
public function __construct()
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

// Intentional parse error (missing double colon after parent keyword). Testing that the sniff is *not* triggered
// in this case.

class FooBar {
public function __construct() {
parent
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

// Intentional parse error (missing parent method opening parenthesis).
// Testing that the sniff is *not* triggered in this case.

class FooBar {
public function __construct() {
parent::__construct
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

// Intentional parse error (missing semicolon).
// Testing that the sniff is *not* triggered in this case.

class FooBar {
public function __construct() {
parent::__construct()
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,23 @@ public function getErrorList()
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
public function getWarningList()
public function getWarningList($testFile='')
{
return [
4 => 1,
16 => 1,
];
switch ($testFile) {
case 'UselessOverridingMethodUnitTest.1.inc':
return [
4 => 1,
16 => 1,
38 => 1,
56 => 1,
];
default:
return [];
}

}//end getWarningList()

Expand Down

0 comments on commit 5a3770e

Please sign in to comment.