mirror of
https://github.com/pestphp/pest.git
synced 2026-03-11 10:17:23 +01:00
feat(presets): reworks code
This commit is contained in:
@ -5,21 +5,27 @@ declare(strict_types=1);
|
||||
namespace Pest\ArchPresets;
|
||||
|
||||
use Pest\Arch\Contracts\ArchExpectation;
|
||||
use Pest\Expectation;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
abstract class AbstractPreset
|
||||
{
|
||||
/**
|
||||
* The expectations.
|
||||
*
|
||||
* @var array<int, ArchExpectation>
|
||||
*/
|
||||
protected array $expectations = [];
|
||||
|
||||
/**
|
||||
* Creates a new preset instance.
|
||||
*
|
||||
* @param array<int, string> $userNamespaces
|
||||
* @param array<int, ArchExpectation> $expectations
|
||||
*/
|
||||
final public function __construct(// @phpstan-ignore-line
|
||||
protected array $userNamespaces,
|
||||
protected array $expectations = [],
|
||||
final public function __construct(
|
||||
private readonly array $userNamespaces,
|
||||
) {
|
||||
//
|
||||
}
|
||||
@ -44,6 +50,20 @@ abstract class AbstractPreset
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the given callback for each namespace.
|
||||
*
|
||||
* @param callable(Expectation<string|null>): ArchExpectation ...$callbacks
|
||||
*/
|
||||
final public function eachUserNamespace(callable ...$callbacks): void
|
||||
{
|
||||
foreach ($this->userNamespaces as $namespace) {
|
||||
foreach ($callbacks as $callback) {
|
||||
$this->expectations[] = $callback(expect($namespace));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes the expectations.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user