diff --git a/src/ArchPresets/AbstractPreset.php b/src/ArchPresets/AbstractPreset.php index b270a023..21d027bf 100644 --- a/src/ArchPresets/AbstractPreset.php +++ b/src/ArchPresets/AbstractPreset.php @@ -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 + */ + protected array $expectations = []; + /** * Creates a new preset instance. * * @param array $userNamespaces - * @param array $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): 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. */ diff --git a/src/ArchPresets/Base.php b/src/ArchPresets/Php.php similarity index 98% rename from src/ArchPresets/Base.php rename to src/ArchPresets/Php.php index 6723904b..22b409b6 100644 --- a/src/ArchPresets/Base.php +++ b/src/ArchPresets/Php.php @@ -7,7 +7,7 @@ namespace Pest\ArchPresets; /** * @internal */ -final class Base extends AbstractPreset +final class Php extends AbstractPreset { /** * Executes the arch preset. diff --git a/src/ArchPresets/Relaxed.php b/src/ArchPresets/Relaxed.php new file mode 100644 index 00000000..bea4d0e3 --- /dev/null +++ b/src/ArchPresets/Relaxed.php @@ -0,0 +1,25 @@ +eachUserNamespace( + fn (Expectation $namespace): ArchExpectation => $namespace->not->toUseStrictTypes(), + fn (Expectation $namespace): ArchExpectation => $namespace->classes()->not->toBeFinal(), + ); + } +} diff --git a/src/ArchPresets/Security.php b/src/ArchPresets/Security.php index 57532736..6d1b6484 100644 --- a/src/ArchPresets/Security.php +++ b/src/ArchPresets/Security.php @@ -4,6 +4,9 @@ declare(strict_types=1); namespace Pest\ArchPresets; +use Pest\Arch\Contracts\ArchExpectation; +use Pest\Expectation; + /** * @internal */ @@ -14,6 +17,10 @@ final class Security extends AbstractPreset */ public function execute(): void { + $this->eachUserNamespace( + fn (Expectation $namespace): ArchExpectation => $namespace->not->toHaveFileSystemPermissions('0777'), + ); + $this->expectations[] = expect([ 'md5', 'sha1', @@ -37,11 +44,5 @@ final class Security extends AbstractPreset 'dl', 'assert', ])->not->toBeUsed(); - - foreach ($this->userNamespaces as $namespace) { - $this->expectations[] = expect($namespace) - ->not - ->toHaveFileSystemPermissions('0777'); - } } } diff --git a/src/ArchPresets/Strict.php b/src/ArchPresets/Strict.php index 250a5859..9e994147 100644 --- a/src/ArchPresets/Strict.php +++ b/src/ArchPresets/Strict.php @@ -4,6 +4,9 @@ declare(strict_types=1); namespace Pest\ArchPresets; +use Pest\Arch\Contracts\ArchExpectation; +use Pest\Expectation; + /** * @internal */ @@ -14,14 +17,15 @@ final class Strict extends AbstractPreset */ public function execute(): void { + $this->eachUserNamespace( + fn (Expectation $namespace): ArchExpectation => $namespace->toUseStrictTypes(), + fn (Expectation $namespace): ArchExpectation => $namespace->classes()->toBeFinal(), + fn (Expectation $namespace): ArchExpectation => $namespace->classes()->not->toBeAbstract(), + ); + $this->expectations[] = expect([ 'sleep', 'usleep', ])->not->toBeUsed(); - - foreach ($this->userNamespaces as $namespace) { - $this->expectations[] = expect($namespace) - ->toUseStrictTypes(); - } } } diff --git a/src/PendingCalls/TestCall.php b/src/PendingCalls/TestCall.php index 7915f075..2fd68457 100644 --- a/src/PendingCalls/TestCall.php +++ b/src/PendingCalls/TestCall.php @@ -355,11 +355,11 @@ final class TestCall /** * Sets the test as "todo". */ - public function todo( - array|string $note = null, - array|string $issue = null, - array|string $assignee = null, - array|string $pr = null, + public function todo(// @phpstan-ignore-line + array|string|null $note = null, + array|string|null $assignee = null, + array|string|null $issue = null, + array|string|null $pr = null, ): self { $this->skip('__TODO__'); @@ -412,6 +412,8 @@ final class TestCall /** * Sets the test assignee(s). + * + * @param array|string $assignee */ public function assignee(array|string $assignee): self { diff --git a/src/Plugins/Parallel/Paratest/WrapperRunner.php b/src/Plugins/Parallel/Paratest/WrapperRunner.php index 6b093764..1c1a1e8b 100644 --- a/src/Plugins/Parallel/Paratest/WrapperRunner.php +++ b/src/Plugins/Parallel/Paratest/WrapperRunner.php @@ -405,6 +405,7 @@ final class WrapperRunner implements RunnerInterface } $testSuite = (new LogMerger)->merge($this->junitFiles); + assert($testSuite instanceof \ParaTest\JUnit\TestSuite); (new Writer)->write( $testSuite, $this->options->configuration->logfileJunit(), diff --git a/src/Preset.php b/src/Preset.php index cc7c8956..1fb79fd8 100644 --- a/src/Preset.php +++ b/src/Preset.php @@ -6,8 +6,8 @@ namespace Pest; use Pest\Arch\Support\Composer; use Pest\ArchPresets\AbstractPreset; -use Pest\ArchPresets\Base; use Pest\ArchPresets\Laravel; +use Pest\ArchPresets\Php; use Pest\ArchPresets\Security; use Pest\ArchPresets\Strict; use Pest\PendingCalls\TestCall; @@ -34,11 +34,11 @@ final class Preset } /** - * Uses the Pest base preset and returns the test call instance. + * Uses the Pest php preset and returns the test call instance. */ - public function base(): Base + public function php(): Php { - return $this->executePreset(new Base($this->baseNamespaces())); + return $this->executePreset(new Php($this->baseNamespaces())); } /** diff --git a/src/TestCaseMethodFilters/AssigneeTestCaseFilter.php b/src/TestCaseMethodFilters/AssigneeTestCaseFilter.php index 2a775693..e21ff032 100644 --- a/src/TestCaseMethodFilters/AssigneeTestCaseFilter.php +++ b/src/TestCaseMethodFilters/AssigneeTestCaseFilter.php @@ -22,6 +22,6 @@ final readonly class AssigneeTestCaseFilter implements TestCaseMethodFilter */ public function accept(TestCaseMethodFactory $factory): bool { - return array_filter($factory->assignees, fn ($assignee): bool => str_starts_with($assignee, $this->assignee)) !== []; + return array_filter($factory->assignees, fn (string $assignee): bool => str_starts_with($assignee, $this->assignee)) !== []; } } diff --git a/tests/Arch.php b/tests/Arch.php index 7e1d0552..0398416a 100644 --- a/tests/Arch.php +++ b/tests/Arch.php @@ -2,7 +2,7 @@ use Pest\Expectation; -arch()->preset()->base()->ignoring([ +arch()->preset()->php()->ignoring([ Expectation::class, 'debug_backtrace', 'var_export',