Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/discovery/src/BootDiscovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ private function discoverPath(string $input, DiscoveryLocation $location, array
} elseif (class_exists($className)) {
$input = new ClassReflector($className);
}
} catch (AssertionError) {
} catch (AssertionError|\Pest\Exceptions\InvalidPestCommand) { // @phpstan-ignore class.notFound
// Workaround for Pest test files autoloading.
// @mago-expect lint:no-empty-catch-clause
}
Expand Down
24 changes: 23 additions & 1 deletion packages/discovery/src/DiscoveryConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

namespace Tempest\Discovery;

use Closure;
use Tempest\Support\Filesystem;

final class DiscoveryConfig
{
private array $skipDiscovery = [];

/** @var array<Closure(string): bool> */
private array $skipUsing = [];

/** @var array<array-key, class-string<\Tempest\Discovery\Discovery>> The loaded discovery classes that will be used during discovery */
public array $classes = [];

Expand All @@ -25,7 +29,25 @@ public static function autoload(string $path): self

public function shouldSkip(string $input): bool
{
return $this->skipDiscovery[$input] ?? false;
if (array_key_exists($input, $this->skipDiscovery)) {
return true;
}

foreach ($this->skipUsing as $closure) {
if ($closure($input) === true) {
return true;
}
}

return false;
}

/** @param (Closure(string): bool) $closure */
public function skipUsing(Closure $closure): self
{
$this->skipUsing[] = $closure;

return $this;
}

public function skipClasses(string ...$classNames): self
Expand Down
Loading