mirror of
https://github.com/pestphp/pest.git
synced 2026-06-07 20:02:13 +02:00
feat(presets): refactors code
This commit is contained in:
54
src/ArchPresets/AbstractPreset.php
Normal file
54
src/ArchPresets/AbstractPreset.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\ArchPresets;
|
||||
|
||||
use Pest\Arch\Contracts\ArchExpectation;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
abstract class AbstractPreset
|
||||
{
|
||||
/**
|
||||
* 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 = [],
|
||||
) {
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the arch preset.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
abstract public function execute(): void;
|
||||
|
||||
/**
|
||||
* Ignores the given "targets" or "dependencies".
|
||||
*
|
||||
* @param array<int, string>|string $targetsOrDependencies
|
||||
*/
|
||||
final public function ignoring(array|string $targetsOrDependencies): void
|
||||
{
|
||||
$this->expectations = array_map(
|
||||
fn (ArchExpectation $expectation): \Pest\Arch\Contracts\ArchExpectation => $expectation->ignoring($targetsOrDependencies),
|
||||
$this->expectations,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes the expectations.
|
||||
*/
|
||||
final public function flush(): void
|
||||
{
|
||||
$this->expectations = [];
|
||||
}
|
||||
}
|
||||
@ -4,24 +4,17 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pest\ArchPresets;
|
||||
|
||||
use Pest\Arch\Contracts\ArchExpectation;
|
||||
use Pest\Contracts\ArchPreset;
|
||||
use Pest\PendingCalls\TestCall;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class Base implements ArchPreset
|
||||
final class Base extends AbstractPreset
|
||||
{
|
||||
/**
|
||||
* Boots the arch preset.
|
||||
*
|
||||
* @param array<string> $baseNamespace
|
||||
* Executes the arch preset.
|
||||
*/
|
||||
public function boot(TestCall $testCall, array $baseNamespace): TestCall|ArchExpectation
|
||||
public function execute(): void
|
||||
{
|
||||
return $testCall // @phpstan-ignore-line
|
||||
->expect(['dd', 'dump', 'ray', 'die', 'var_dump', 'sleep', 'eval', 'ini_set'])
|
||||
$this->expectations[] = expect(['dd', 'dump', 'ray', 'die', 'var_dump', 'sleep', 'eval', 'ini_set'])
|
||||
->not
|
||||
->toBeUsed();
|
||||
}
|
||||
|
||||
@ -4,25 +4,19 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pest\ArchPresets;
|
||||
|
||||
use Pest\Arch\Contracts\ArchExpectation;
|
||||
use Pest\Contracts\ArchPreset;
|
||||
use Pest\PendingCalls\TestCall;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class Strict implements ArchPreset
|
||||
final class Strict extends AbstractPreset
|
||||
{
|
||||
/**
|
||||
* Boots the arch preset.
|
||||
*
|
||||
* @param array<string> $baseNamespaces
|
||||
* Executes the arch preset.
|
||||
*/
|
||||
public function boot(TestCall $testCall, array $baseNamespaces): TestCall|ArchExpectation
|
||||
public function execute(): void
|
||||
{
|
||||
return $testCall // @phpstan-ignore-line
|
||||
->expect($baseNamespaces)
|
||||
->each
|
||||
->toUseStrictTypes();
|
||||
foreach ($this->userNamespaces as $namespace) {
|
||||
$this->expectations[] = expect($namespace)
|
||||
->toUseStrictTypes();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user