rspec/rules/S5899/php/rule.adoc

61 lines
1.5 KiB
Plaintext

== Why is this an issue?
The PHPUnit test runner does execute public methods defined within test classes that have a name starting with _"test"_ or the _@test_ annotation. Methods that do not convey to this will not get executed.
This rule raises an issue on methods marked as test methods (by name or annotation) but do not have a public visibility. An issue is also raised on public methods that are not marked as tests, do contain assertions, and are not called from within another discoverable test method within the class. No issues are raised in abstract classes, or on public static method which provides data.
=== Noncompliant code example
[source,php]
----
class MyTest extends \PHPUnit\Framework\TestCase {
private function testA() { // Noncompliant
$this->assertTrue(getValue());
}
public function b() { // Noncompliant
$this->assertTrue(getValue());
}
}
----
=== Compliant solution
[source,php]
----
class MyTest extends \PHPUnit\Framework\TestCase {
public function testA() { // Compliant
$this->assertTrue(getValue());
}
public function testB() {
$this->b();
}
public function b() { // Compliant
$this->assertTrue(getValue());
}
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Rename this method so that it starts with "test" or remove this unused helper.
=== Highlighting
Primary: the name of the method.
endif::env-github,rspecator-view[]