From 5ddbabff2910d870549177a13d8729113db1aac3 Mon Sep 17 00:00:00 2001 From: Sami Aji Date: Thu, 16 Apr 2026 08:20:30 -0400 Subject: [PATCH 1/8] feat(depends-external): stub test --- tests/Features/DependsExternal.php | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 tests/Features/DependsExternal.php diff --git a/tests/Features/DependsExternal.php b/tests/Features/DependsExternal.php new file mode 100644 index 000000000..ddd16eda3 --- /dev/null +++ b/tests/Features/DependsExternal.php @@ -0,0 +1,6 @@ +toBe('first'); + expect($second)->toBe('second'); +})->dependsExternal('Tests\Features\Depends', 'first', 'second'); From 88e42c35b425c082a10ffcf31be0518f3efc02bc Mon Sep 17 00:00:00 2001 From: Sami Aji Date: Thu, 16 Apr 2026 08:22:35 -0400 Subject: [PATCH 2/8] feat(depends-external): add & set `dependsExternal` --- src/Factories/TestCaseMethodFactory.php | 30 ++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/Factories/TestCaseMethodFactory.php b/src/Factories/TestCaseMethodFactory.php index f0a734016..a9bf46ca4 100644 --- a/src/Factories/TestCaseMethodFactory.php +++ b/src/Factories/TestCaseMethodFactory.php @@ -15,6 +15,7 @@ use PHPUnit\Framework\Assert; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Depends; +use PHPUnit\Framework\Attributes\DependsExternal; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\TestCase; @@ -102,6 +103,19 @@ final class TestCaseMethodFactory */ public array $depends = []; + /** + * The test's external dependencies (tests in other Pest test files). + * + * Example: + * [ + * 'testCase' => 'Tests\Features\Depends', + * 'test' => 'first', + * ] + * + * @var array + */ + public array $dependsExternal = []; + /** * The test's groups. * @@ -183,7 +197,7 @@ public function getClosure(): Closure */ public function receivesArguments(): bool { - return $this->datasets !== [] || $this->depends !== [] || $this->repetitions > 1; + return $this->datasets !== [] || $this->depends !== [] || $this->dependsExternal !== [] || $this->repetitions > 1; } /** @@ -220,6 +234,20 @@ public function buildForEvaluation(): string ); } + foreach ($this->dependsExternal as $externalDepend) { + $depend = Str::evaluable( + $this->describing === [] + ? $externalDepend['test'] + : Str::describe($this->describing, $externalDepend['test']) + ); + + $className = 'P\\'.$externalDepend['testCase']; + $this->attributes[] = new Attribute( + DependsExternal::class, + [$className, $depend], + ); + } + if ($this->datasets !== [] || $this->repetitions > 1) { $dataProviderName = $methodName.'_dataset'; $this->attributes[] = new Attribute( From e409cd9e6a121c340b779b8fef84a921fcb54fdc Mon Sep 17 00:00:00 2001 From: Sami Aji Date: Thu, 16 Apr 2026 08:23:02 -0400 Subject: [PATCH 3/8] feat(depends-external): add `dependsExternal` fn --- src/PendingCalls/TestCall.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/PendingCalls/TestCall.php b/src/PendingCalls/TestCall.php index ccf9b4f9b..f03c61eef 100644 --- a/src/PendingCalls/TestCall.php +++ b/src/PendingCalls/TestCall.php @@ -208,6 +208,24 @@ public function depends(string ...$depends): self return $this; } + /** + * Sets external test dependencies from another Pest test file reference. + * + * @param string $testCase The Pest test reference (e.g. "Tests\Features\Depends") + * @param string ...$depends One or more test descriptions to depend on + */ + public function dependsExternal(string $testCase, string ...$depends): self + { + foreach ($depends as $depend) { + $this->testCaseMethod->dependsExternal[] = [ + 'testCase' => $testCase, + 'test' => $depend, + ]; + } + + return $this; + } + /** * Sets the test group(s). */ From 6a7446051755006f14819f0a95f33464241e9523 Mon Sep 17 00:00:00 2001 From: Sami Aji Date: Thu, 16 Apr 2026 11:53:19 -0400 Subject: [PATCH 4/8] feat(depends-external): add test variations --- tests/Features/DependsExternal.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/Features/DependsExternal.php b/tests/Features/DependsExternal.php index ddd16eda3..0f128d00a 100644 --- a/tests/Features/DependsExternal.php +++ b/tests/Features/DependsExternal.php @@ -1,6 +1,20 @@ toBe(['first', 'second']); +})->dependsExternal('Tests\Features\Depends', 'first', 'second'); + +test('depends on tests in an external file', function (string $first, string $second) { + expect($first)->toBe('first'); + expect($second)->toBe('second'); +})->dependsExternal('Tests\Features\Depends', 'first', 'second'); + +test('depends on tests in an external file with spread arguments', function (string ...$params) { + expect(func_get_args())->toBe($params); + expect($params)->toBe(['first', 'second']); +})->dependsExternal('Tests\Features\Depends', 'first', 'second'); + +test('depends on tests in an external file with defined arguments', function (string $first, string $second) { expect($first)->toBe('first'); expect($second)->toBe('second'); })->dependsExternal('Tests\Features\Depends', 'first', 'second'); From 3c9206430e68ce180a97fafb89b42e5a2e8fa1d2 Mon Sep 17 00:00:00 2001 From: Sami Aji Date: Thu, 16 Apr 2026 11:54:58 -0400 Subject: [PATCH 5/8] chore(depends-external): run linter --- overrides/Runner/TestSuiteLoader.php | 1 - src/Factories/TestCaseMethodFactory.php | 2 +- src/PendingCalls/TestCall.php | 4 ++-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/overrides/Runner/TestSuiteLoader.php b/overrides/Runner/TestSuiteLoader.php index 9006d08cd..964fd3157 100644 --- a/overrides/Runner/TestSuiteLoader.php +++ b/overrides/Runner/TestSuiteLoader.php @@ -179,7 +179,6 @@ public function load(string $suiteClassFile): ReflectionClass if (! class_exists($suiteClassName, false)) { return $this->exceptionFor($suiteClassName, $suiteClassFile); } - // @codeCoverageIgnoreEnd if ($class->isSubclassOf(TestCase::class) && ! $class->isAbstract()) { diff --git a/src/Factories/TestCaseMethodFactory.php b/src/Factories/TestCaseMethodFactory.php index a9bf46ca4..5df17cf65 100644 --- a/src/Factories/TestCaseMethodFactory.php +++ b/src/Factories/TestCaseMethodFactory.php @@ -112,7 +112,7 @@ final class TestCaseMethodFactory * 'test' => 'first', * ] * - * @var array + * @var array */ public array $dependsExternal = []; diff --git a/src/PendingCalls/TestCall.php b/src/PendingCalls/TestCall.php index f03c61eef..ef0d7b943 100644 --- a/src/PendingCalls/TestCall.php +++ b/src/PendingCalls/TestCall.php @@ -211,8 +211,8 @@ public function depends(string ...$depends): self /** * Sets external test dependencies from another Pest test file reference. * - * @param string $testCase The Pest test reference (e.g. "Tests\Features\Depends") - * @param string ...$depends One or more test descriptions to depend on + * @param string $testCase The Pest test reference (e.g. "Tests\Features\Depends") + * @param string ...$depends One or more test descriptions to depend on */ public function dependsExternal(string $testCase, string ...$depends): self { From 608da46c3e2537d750303330f999b34c9f1d4dcb Mon Sep 17 00:00:00 2001 From: Sami Aji Date: Thu, 16 Apr 2026 14:05:51 -0400 Subject: [PATCH 6/8] chore(depends-external): update test & assertion counts, `success.txt` --- tests/.snapshots/success.txt | 8 +++++++- tests/Visual/Parallel.php | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index c19ebf8b7..587f9e2b1 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -289,6 +289,12 @@ ✓ describe block → nested describe → third in nested describe ✓ depends on test after describe block + PASS Tests\Features\DependsExternal + ✓ dependsExternal + ✓ depends on tests in an external file + ✓ depends on tests in an external file with spread arguments + ✓ depends on tests in an external file with defined arguments + PASS Tests\Features\DependsInheritance ✓ it is a test ✓ it uses correct parent class @@ -1901,4 +1907,4 @@ ✓ pass with dataset with ('my-datas-set-value') ✓ within describe → pass with dataset with ('my-datas-set-value') - Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 35 skipped, 1294 passed (2971 assertions) \ No newline at end of file + Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 35 skipped, 1298 passed (2978 assertions) \ No newline at end of file diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index 0d1f4d64c..8262ffb02 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -23,13 +23,13 @@ $file = file_get_contents(__FILE__); $file = preg_replace( '/\$expected = \'.*?\';/', - "\$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1278 passed (2920 assertions)';", + "\$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1282 passed (2927 assertions)';", $file, ); file_put_contents(__FILE__, $file); } - $expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1278 passed (2920 assertions)'; + $expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1282 passed (2927 assertions)'; expect($output) ->toContain("Tests: {$expected}") From d25dffc4ebd704f24196db4c9ace7357f5d50584 Mon Sep 17 00:00:00 2001 From: Sami Aji Date: Thu, 16 Apr 2026 14:46:58 -0400 Subject: [PATCH 7/8] feat(depends-external): add tests for chaining --- tests/Features/DependsExternal.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/Features/DependsExternal.php b/tests/Features/DependsExternal.php index 0f128d00a..960098347 100644 --- a/tests/Features/DependsExternal.php +++ b/tests/Features/DependsExternal.php @@ -4,6 +4,16 @@ expect(func_get_args())->toBe(['first', 'second']); })->dependsExternal('Tests\Features\Depends', 'first', 'second'); +test('dependsExternal chained', function () { + expect(func_get_args())->toBe(['first', 'second']); +})->dependsExternal('Tests\Features\Depends', 'first') + ->dependsExternal('Tests\Features\Depends', 'second'); + +test('dependsExternal chained, reversed', function () { + expect(func_get_args())->toBe(['second', 'first']); +})->dependsExternal('Tests\Features\Depends', 'second') + ->dependsExternal('Tests\Features\Depends', 'first'); + test('depends on tests in an external file', function (string $first, string $second) { expect($first)->toBe('first'); expect($second)->toBe('second'); From 67f3f24ecf2a89030bc153f2015cba7313c683c7 Mon Sep 17 00:00:00 2001 From: Sami Aji Date: Thu, 16 Apr 2026 14:49:05 -0400 Subject: [PATCH 8/8] chore(depends-external): update test & assertion counts, success.txt --- tests/.snapshots/success.txt | 4 +++- tests/Visual/Parallel.php | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 587f9e2b1..b05916b2b 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -291,6 +291,8 @@ PASS Tests\Features\DependsExternal ✓ dependsExternal + ✓ dependsExternal chained + ✓ dependsExternal chained, reversed ✓ depends on tests in an external file ✓ depends on tests in an external file with spread arguments ✓ depends on tests in an external file with defined arguments @@ -1907,4 +1909,4 @@ ✓ pass with dataset with ('my-datas-set-value') ✓ within describe → pass with dataset with ('my-datas-set-value') - Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 35 skipped, 1298 passed (2978 assertions) \ No newline at end of file + Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 35 skipped, 1300 passed (2980 assertions) \ No newline at end of file diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index 8262ffb02..d6ff012f7 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -23,13 +23,13 @@ $file = file_get_contents(__FILE__); $file = preg_replace( '/\$expected = \'.*?\';/', - "\$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1282 passed (2927 assertions)';", + "\$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1284 passed (2929 assertions)';", $file, ); file_put_contents(__FILE__, $file); } - $expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1282 passed (2927 assertions)'; + $expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1284 passed (2929 assertions)'; expect($output) ->toContain("Tests: {$expected}")