mirror of
https://github.com/pestphp/pest.git
synced 2026-03-11 02:07:23 +01:00
feat: custom presets
This commit is contained in:
@ -15,7 +15,7 @@ abstract class AbstractPreset // @pest-arch-ignore-line
|
||||
/**
|
||||
* The expectations.
|
||||
*
|
||||
* @var array<int, ArchExpectation>
|
||||
* @var array<int, Expectation<mixed>|ArchExpectation>
|
||||
*/
|
||||
protected array $expectations = [];
|
||||
|
||||
@ -24,7 +24,7 @@ abstract class AbstractPreset // @pest-arch-ignore-line
|
||||
*
|
||||
* @param array<int, string> $userNamespaces
|
||||
*/
|
||||
final public function __construct(
|
||||
public function __construct(
|
||||
private readonly array $userNamespaces,
|
||||
) {
|
||||
//
|
||||
@ -45,7 +45,7 @@ abstract class AbstractPreset // @pest-arch-ignore-line
|
||||
final public function ignoring(array|string $targetsOrDependencies): void
|
||||
{
|
||||
$this->expectations = array_map(
|
||||
fn (ArchExpectation $expectation): \Pest\Arch\Contracts\ArchExpectation => $expectation->ignoring($targetsOrDependencies),
|
||||
fn (ArchExpectation|Expectation $expectation): Expectation|ArchExpectation => $expectation instanceof ArchExpectation ? $expectation->ignoring($targetsOrDependencies) : $expectation,
|
||||
$this->expectations,
|
||||
);
|
||||
}
|
||||
|
||||
45
src/ArchPresets/Custom.php
Normal file
45
src/ArchPresets/Custom.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\ArchPresets;
|
||||
|
||||
use Closure;
|
||||
use Pest\Arch\Contracts\ArchExpectation;
|
||||
use Pest\Expectation;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class Custom extends AbstractPreset
|
||||
{
|
||||
/**
|
||||
* Creates a new preset instance.
|
||||
*
|
||||
* @param array<int, string> $userNamespaces
|
||||
* @param Closure(array<int, string>): array<Expectation<mixed>|ArchExpectation> $execute
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly array $userNamespaces,
|
||||
private readonly string $name,
|
||||
private readonly Closure $execute,
|
||||
) {
|
||||
parent::__construct($userNamespaces);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the preset.
|
||||
*/
|
||||
public function name(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the arch preset.
|
||||
*/
|
||||
public function execute(): void
|
||||
{
|
||||
$this->expectations = ($this->execute)($this->userNamespaces);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user