mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
feat: initial work on presets
This commit is contained in:
28
src/ArchPresets/Base.php
Normal file
28
src/ArchPresets/Base.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
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
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Boots the arch preset.
|
||||||
|
*
|
||||||
|
* @param array<string> $baseNamespace
|
||||||
|
*/
|
||||||
|
public function boot(TestCall $testCall, array $baseNamespace): TestCall|ArchExpectation
|
||||||
|
{
|
||||||
|
return $testCall
|
||||||
|
->expect(['dd', 'dump', 'ray', 'die', 'var_dump', 'sleep'])
|
||||||
|
->not
|
||||||
|
->toBeUsed();
|
||||||
|
}
|
||||||
|
}
|
||||||
28
src/ArchPresets/Strict.php
Normal file
28
src/ArchPresets/Strict.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
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
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Boots the arch preset.
|
||||||
|
*
|
||||||
|
* @param array<string> $baseNamespaces
|
||||||
|
*/
|
||||||
|
public function boot(TestCall $testCall, array $baseNamespaces): TestCall|ArchExpectation
|
||||||
|
{
|
||||||
|
return $testCall
|
||||||
|
->expect($baseNamespaces)
|
||||||
|
->each
|
||||||
|
->toUseStrictTypes();
|
||||||
|
}
|
||||||
|
}
|
||||||
21
src/Contracts/ArchPreset.php
Normal file
21
src/Contracts/ArchPreset.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Pest\Contracts;
|
||||||
|
|
||||||
|
use Pest\Arch\Contracts\ArchExpectation;
|
||||||
|
use Pest\PendingCalls\TestCall;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
interface ArchPreset
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Boots the arch preset.
|
||||||
|
*
|
||||||
|
* @param array<int, string> $baseNamespaces
|
||||||
|
*/
|
||||||
|
public function boot(TestCall $testCall, array $baseNamespaces): TestCall|ArchExpectation;
|
||||||
|
}
|
||||||
@ -12,6 +12,7 @@ use Pest\Factories\TestCaseMethodFactory;
|
|||||||
use Pest\Mutate\Decorators\TestCallDecorator as MutationTestCallDecorator;
|
use Pest\Mutate\Decorators\TestCallDecorator as MutationTestCallDecorator;
|
||||||
use Pest\PendingCalls\Concerns\Describable;
|
use Pest\PendingCalls\Concerns\Describable;
|
||||||
use Pest\Plugins\Only;
|
use Pest\Plugins\Only;
|
||||||
|
use Pest\Preset;
|
||||||
use Pest\Support\Backtrace;
|
use Pest\Support\Backtrace;
|
||||||
use Pest\Support\Exporter;
|
use Pest\Support\Exporter;
|
||||||
use Pest\Support\HigherOrderCallables;
|
use Pest\Support\HigherOrderCallables;
|
||||||
@ -521,4 +522,12 @@ final class TestCall
|
|||||||
$testCase->attributes = array_merge($testCase->attributes, $this->testCaseFactoryAttributes);
|
$testCase->attributes = array_merge($testCase->attributes, $this->testCaseFactoryAttributes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses the given preset on the test.
|
||||||
|
*/
|
||||||
|
public function preset(): Preset
|
||||||
|
{
|
||||||
|
return new Preset($this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
58
src/Preset.php
Normal file
58
src/Preset.php
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Pest;
|
||||||
|
|
||||||
|
use Pest\Arch\Contracts\ArchExpectation;
|
||||||
|
use Pest\Arch\Support\Composer;
|
||||||
|
use Pest\PendingCalls\TestCall;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class Preset
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The application / package base namespaces.
|
||||||
|
*/
|
||||||
|
private static ?array $baseNamespaces = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new preset instance.
|
||||||
|
*/
|
||||||
|
public function __construct(private readonly TestCall $testCall)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses the Pest base preset and returns the test call instance.
|
||||||
|
*/
|
||||||
|
public function base(): TestCall|ArchExpectation
|
||||||
|
{
|
||||||
|
return (new ArchPresets\Base)->boot($this->testCall, $this->baseNamespaces());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses the Pest strict preset and returns the test call instance.
|
||||||
|
*/
|
||||||
|
public function strict(): TestCall
|
||||||
|
{
|
||||||
|
(new ArchPresets\Strict)->boot($this->testCall, $this->baseNamespaces());
|
||||||
|
|
||||||
|
return $this->testCall;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the base namespaces for the application / package.
|
||||||
|
*/
|
||||||
|
private function baseNamespaces(): array
|
||||||
|
{
|
||||||
|
if (self::$baseNamespaces === null) {
|
||||||
|
self::$baseNamespaces = Composer::userNamespaces();
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::$baseNamespaces;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,5 +1,7 @@
|
|||||||
|
|
||||||
PASS Tests\Arch
|
PASS Tests\Arch
|
||||||
|
✓ expect ['dd', 'dump', 'ray', …] → not → toBeUsed → ignoring 'Pest\Expectation'
|
||||||
|
✓ expect ['Pest'] → each → toUseStrictTypes
|
||||||
✓ globals
|
✓ globals
|
||||||
✓ dependencies
|
✓ dependencies
|
||||||
✓ contracts
|
✓ contracts
|
||||||
@ -1266,7 +1268,7 @@
|
|||||||
✓ closure was bound to CustomTestCase
|
✓ closure was bound to CustomTestCase
|
||||||
|
|
||||||
PASS Tests\Playground
|
PASS Tests\Playground
|
||||||
✓ basic
|
✓ expect ['Pest'] → each → toUseStrictTypes
|
||||||
|
|
||||||
PASS Tests\Plugins\Traits
|
PASS Tests\Plugins\Traits
|
||||||
✓ it allows global uses
|
✓ it allows global uses
|
||||||
@ -1461,4 +1463,4 @@
|
|||||||
WARN Tests\Visual\Version
|
WARN Tests\Visual\Version
|
||||||
- visual snapshot of help command output
|
- visual snapshot of help command output
|
||||||
|
|
||||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 24 skipped, 1042 passed (2563 assertions)
|
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 24 skipped, 1044 passed (2565 assertions)
|
||||||
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
use Pest\Expectation;
|
use Pest\Expectation;
|
||||||
|
|
||||||
|
arch()->preset()->base()->ignoring(Expectation::class);
|
||||||
|
|
||||||
|
arch()->preset()->strict();
|
||||||
|
|
||||||
arch('globals')
|
arch('globals')
|
||||||
->expect(['dd', 'dump', 'ray', 'die', 'var_dump', 'sleep'])
|
->expect(['dd', 'dump', 'ray', 'die', 'var_dump', 'sleep'])
|
||||||
->not->toBeUsed()
|
->not->toBeUsed()
|
||||||
@ -30,4 +34,6 @@ arch('contracts')
|
|||||||
'NunoMaduro\Collision\Contracts',
|
'NunoMaduro\Collision\Contracts',
|
||||||
'Pest\Factories\TestCaseMethodFactory',
|
'Pest\Factories\TestCaseMethodFactory',
|
||||||
'Symfony\Component\Console',
|
'Symfony\Component\Console',
|
||||||
|
'Pest\Arch\Contracts',
|
||||||
|
'Pest\PendingCalls',
|
||||||
])->toBeInterfaces();
|
])->toBeInterfaces();
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
test('basic', function () {
|
arch()->preset()->strict();
|
||||||
expect(true)->toBeTrue();
|
|
||||||
});
|
|
||||||
|
|||||||
@ -16,7 +16,7 @@ $run = function () {
|
|||||||
|
|
||||||
test('parallel', function () use ($run) {
|
test('parallel', function () use ($run) {
|
||||||
expect($run('--exclude-group=integration'))
|
expect($run('--exclude-group=integration'))
|
||||||
->toContain('Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 1028 passed (2531 assertions)')
|
->toContain('Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 1030 passed (2533 assertions)')
|
||||||
->toContain('Parallel: 3 processes');
|
->toContain('Parallel: 3 processes');
|
||||||
})->skipOnWindows();
|
})->skipOnWindows();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user