Skip to content

Commit

Permalink
support get, is and has as getter
Browse files Browse the repository at this point in the history
  • Loading branch information
sHorst committed May 5, 2024
1 parent 903b16f commit 23b2a80
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions Classes/Domain/Model/ModelUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,17 @@ public function testNotTestedStringAndIntegerAttributes(): void
}

foreach (get_class_methods(get_class($this->subject)) as $method) {
$type = substr($method, 0, 3);
$attribute = lcfirst(substr($method, 3));
$attribute = lcfirst(substr($method, str_starts_with($method, 'is') ? 2 : 3));
$setter = 'set' . ucfirst($attribute);
$getter = 'get' . ucfirst($attribute);

if (str_starts_with($method, 'get') || str_starts_with($method, 'is') || str_starts_with($method, 'has')) {
$getter = $method;
} else {
continue;
}

// only test, if getter and setter exists and local testClass does not implement this test
if (
$type === 'get' &&
method_exists($this->subject, $setter) &&
!method_exists($this, 'test' . ucfirst($attribute))
) {
Expand Down Expand Up @@ -287,7 +290,7 @@ public function testNotTestedStringAndIntegerAttributes(): void
self::assertEquals($testDate, $this->subject->$getter());
break;
}
} catch (ReflectionException $exception) {
} catch (ReflectionException) {
// ignore attribute
}
}
Expand Down

0 comments on commit 23b2a80

Please sign in to comment.