Skip to content

Commit

Permalink
RunTestsTrait::runTests(): $throwException parameter added
Browse files Browse the repository at this point in the history
  • Loading branch information
zozlak committed Dec 18, 2024
1 parent c74987a commit 94d3c3e
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/acdhOeaw/arche/doorkeeper/RunTestsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,16 @@
*/
trait RunTestsTrait {

/**
*
* @param bool $throwException if `true`, the method throws a DoorkeeperException
* on errors or null otherwise. If `false`, method returns a (possibly empty)
* array of DoorkeeperExceptions.
* @return array<DoorkeeperException>|null
*/
public function runTests(string $attribute = CheckAttribute::class,
int $filter = ReflectionMethod::IS_PUBLIC): void {
int $filter = ReflectionMethod::IS_PUBLIC,
bool $throwException = true): array | null {
$rc = new ReflectionClass(static::class);
$closures = [];
foreach ($rc->getMethods($filter) as $method) {
Expand All @@ -52,11 +60,12 @@ public function runTests(string $attribute = CheckAttribute::class,
try {
$i();
} catch (DoorkeeperException $ex) {
$errors[] = $ex->getMessage();
$errors[] = $ex;
}
}
if (count($errors) > 0) {
throw new DoorkeeperException(implode("\n", $errors));
if (count($errors) > 0 && $throwException) {
throw new DoorkeeperException(implode("\n", array_map(fn($x) => $x->getMessage(), $errors)));
}
return $throwException ? null : $errors;
}
}

0 comments on commit 94d3c3e

Please sign in to comment.