Skip to content

Commit

Permalink
Merge pull request #116 from aik099/ignore-static-test-methods
Browse files Browse the repository at this point in the history
Exclude assertion methods during the test suite building
  • Loading branch information
aik099 authored Mar 12, 2024
2 parents 12f6504 + 9daeea5 commit 1bd5388
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions library/aik099/PHPUnit/TestSuite/AbstractTestSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ public function addTestMethods($class_name)

if ( \method_exists($this, 'isTestMethod') ) {
// PHPUnit < 8.0 is calling "isTestMethod" inside "TestSuite::addTestMethod".
foreach ( $class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method ) {
foreach ( $this->getTestMethods($class) as $method ) {
$this->addTestMethod($class, $method);
}
}
else {
// PHPUnit >= 8.0 is calling "TestUtil::isTestMethod" outside of "TestSuite::addTestMethod".
foreach ( $class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method ) {
foreach ( $this->getTestMethods($class) as $method ) {
if ( TestUtil::isTestMethod($method) ) {
$this->addTestMethod($class, $method);
}
Expand All @@ -63,6 +63,22 @@ public function addTestMethods($class_name)
return $this;
}

/**
* Returns test methods.
*
* @param \ReflectionClass $class Reflection class.
*
* @return \ReflectionMethod[]
*/
protected function getTestMethods(\ReflectionClass $class)
{
$ret = $class->getMethods(\ReflectionMethod::IS_PUBLIC);

return \array_filter($ret, function (\ReflectionMethod $method) {
return !$method->isStatic();
});
}

/**
* Sets session strategy manager recursively to all tests.
*
Expand Down

0 comments on commit 1bd5388

Please sign in to comment.