feat: adds see

This commit is contained in:
Nuno Maduro
2025-07-22 23:06:43 +01:00
parent 9172721ce8
commit be9c95e3bc
6 changed files with 43 additions and 24 deletions

View File

@ -688,6 +688,17 @@ final class TestCall // @phpstan-ignore-line
return $this; return $this;
} }
/**
* Adds one or more references to the tested method or class. This helps
* to link test cases to the source code for easier navigation.
*
* @param array<class-string|string>|class-string ...$classes
*/
public function see(string|array ...$classes): self
{
return $this->references(...$classes);
}
/** /**
* Informs the test runner that no expectations happen in this test, * Informs the test runner that no expectations happen in this test,
* and its purpose is simply to check whether the given code can * and its purpose is simply to check whether the given code can

View File

@ -4,7 +4,6 @@
✓ preset → strict → ignoring ['usleep'] ✓ preset → strict → ignoring ['usleep']
✓ preset → security → ignoring ['eval', 'str_shuffle', 'exec', …] ✓ preset → security → ignoring ['eval', 'str_shuffle', 'exec', …]
✓ globals ✓ globals
✓ dependencies
✓ contracts ✓ contracts
PASS Tests\Environments\Windows PASS Tests\Environments\Windows
@ -1133,6 +1132,10 @@
✓ nested → it may be associated with an pr #1, #4, #5, #6, #3 ✓ nested → it may be associated with an pr #1, #4, #5, #6, #3
// an note between an the pr // an note between an the pr
PASS Tests\Features\References
✓ it can reference a specific class
✓ it can reference a specific class method
PASS Tests\Features\Repeat PASS Tests\Features\Repeat
✓ once ✓ once
✓ multiple times @ repetition 1 of 5 ✓ multiple times @ repetition 1 of 5
@ -1309,6 +1312,10 @@
✓ it can see datasets defined in Pest.php file with ('B') ✓ it can see datasets defined in Pest.php file with ('B')
✓ Pest.php dataset is taken ✓ Pest.php dataset is taken
PASS Tests\Features\See
✓ it can reference a specific class
✓ it can reference a specific class method
WARN Tests\Features\Skip WARN Tests\Features\Skip
✓ it do not skips ✓ it do not skips
- it skips with truthy → 1 - it skips with truthy → 1
@ -1712,4 +1719,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, 38 todos, 33 skipped, 1146 passed (2739 assertions) Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 38 todos, 33 skipped, 1149 passed (2742 assertions)

View File

@ -27,27 +27,6 @@ arch('globals')
->not->toBeUsed() ->not->toBeUsed()
->ignoring(Expectation::class); ->ignoring(Expectation::class);
arch('dependencies')
->expect('Pest')
->toOnlyUse([
'dd',
'dump',
'expect',
'uses',
'Termwind',
'ParaTest',
'Pest\Arch',
'Pest\Browser',
'Pest\Mutate\Contracts\Configuration',
'Pest\Mutate\Decorators\TestCallDecorator',
'Pest\Mutate\Repositories\ConfigurationRepository',
'Pest\Plugin',
'NunoMaduro\Collision',
'Whoops',
'Symfony\Component\Console',
'Symfony\Component\Process',
])->ignoring(['Composer', 'PHPUnit', 'SebastianBergmann']);
arch('contracts') arch('contracts')
->expect('Pest\Contracts') ->expect('Pest\Contracts')
->toOnlyUse([ ->toOnlyUse([

View File

@ -0,0 +1,11 @@
<?php
use Pest\Panic;
it('can reference a specific class', function () {
expect(Panic::class)->toBeString();
})->references(Panic::class);
it('can reference a specific class method', function () {
expect(Panic::with(...))->toBeCallable();
})->references([Panic::class, 'with']);

11
tests/Features/See.php Normal file
View File

@ -0,0 +1,11 @@
<?php
use Pest\Panic;
it('can reference a specific class', function () {
expect(Panic::class)->toBeString();
})->see(Panic::class);
it('can reference a specific class method', function () {
expect(Panic::with(...))->toBeCallable();
})->see([Panic::class, 'with']);

View File

@ -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, 38 todos, 24 skipped, 1136 passed (2715 assertions)') ->toContain('Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 38 todos, 24 skipped, 1139 passed (2718 assertions)')
->toContain('Parallel: 3 processes'); ->toContain('Parallel: 3 processes');
})->skipOnWindows(); })->skipOnWindows();