Skip to content

Commit 155e5b0

Browse files
Motivated by #4471, do not even try to add non-public methods as test methods
1 parent bc968ed commit 155e5b0

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

src/Framework/TestSuite.php

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ public function __construct($theClass = '', string $name = '')
192192
continue;
193193
}
194194

195+
if (!TestUtil::isTestMethod($method)) {
196+
continue;
197+
}
198+
195199
$this->addTestMethod($theClass, $method);
196200
}
197201

@@ -744,26 +748,8 @@ protected function createResult(): TestResult
744748
*/
745749
protected function addTestMethod(\ReflectionClass $class, \ReflectionMethod $method): void
746750
{
747-
if (!TestUtil::isTestMethod($method)) {
748-
return;
749-
}
750-
751751
$methodName = $method->getName();
752752

753-
if (!$method->isPublic()) {
754-
$this->addTest(
755-
new WarningTestCase(
756-
\sprintf(
757-
'Test method "%s" in test class "%s" is not public.',
758-
$methodName,
759-
$class->getName()
760-
)
761-
)
762-
);
763-
764-
return;
765-
}
766-
767753
$test = (new TestBuilder)->build($class, $methodName);
768754

769755
if ($test instanceof TestCase || $test instanceof DataProviderTestSuite) {

src/Util/Test.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,10 @@ public static function getHookMethods(string $className): array
519519

520520
public static function isTestMethod(\ReflectionMethod $method): bool
521521
{
522+
if (!$method->isPublic()) {
523+
return false;
524+
}
525+
522526
if (\strpos($method->getName(), 'test') === 0) {
523527
return true;
524528
}

tests/unit/Framework/TestSuiteTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function testNotPublicTestCase(): void
7676
{
7777
$suite = new TestSuite(\NotPublicTestCase::class);
7878

79-
$this->assertCount(2, $suite);
79+
$this->assertCount(1, $suite);
8080
}
8181

8282
public function testNotVoidTestCase(): void

0 commit comments

Comments
 (0)