From 0c57142c03a796975a353f92237fb2f083bb8059 Mon Sep 17 00:00:00 2001 From: jshayes Date: Fri, 11 Oct 2024 21:24:08 -0400 Subject: [PATCH] Fix an issue where a describe block will prevent a beforeEach call from executing --- src/PendingCalls/DescribeCall.php | 10 ++++++---- tests/.snapshots/success.txt | 3 ++- tests/Features/Describe.php | 12 ++++++++++++ tests/Visual/Parallel.php | 2 +- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/PendingCalls/DescribeCall.php b/src/PendingCalls/DescribeCall.php index 267c875a..4735ecce 100644 --- a/src/PendingCalls/DescribeCall.php +++ b/src/PendingCalls/DescribeCall.php @@ -15,8 +15,10 @@ final class DescribeCall { /** * The current describe call. + * + * @var string[] */ - private static ?string $describing = null; + private static array $describing = []; /** * The describe "before each" call. @@ -40,7 +42,7 @@ public function __construct( */ public static function describing(): ?string { - return self::$describing; + return self::$describing[count(self::$describing) - 1] ?? null; } /** @@ -50,12 +52,12 @@ public function __destruct() { unset($this->currentBeforeEachCall); - self::$describing = $this->description; + self::$describing[] = $this->description; try { ($this->tests)(); } finally { - self::$describing = null; + array_pop(self::$describing); } } diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index da75f2d2..d0e4c943 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -215,6 +215,7 @@ ✓ depends on describe → bar ✓ depends on describe using with → foo with (3) ✓ depends on describe using with → bar with (3) + ✓ with test after describe → it should run the before each PASS Tests\Features\DescriptionLess ✓ get 'foo' @@ -1584,4 +1585,4 @@ WARN Tests\Visual\Version - visual snapshot of help command output - Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 17 todos, 28 skipped, 1095 passed (2648 assertions) \ No newline at end of file + Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 17 todos, 28 skipped, 1096 passed (2649 assertions) \ No newline at end of file diff --git a/tests/Features/Describe.php b/tests/Features/Describe.php index 64bf3453..836b0fc8 100644 --- a/tests/Features/Describe.php +++ b/tests/Features/Describe.php @@ -96,3 +96,15 @@ expect($foo + $foo)->toBe(6); })->depends('foo'); })->with([3]); + +describe('with test after describe', function () { + beforeEach(function () { + $this->count++; + }); + + describe('foo', function () {}); + + it('should run the before each', function () { + expect($this->count)->toBe(2); + }); +}); diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index 59f7263a..8efb514c 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -16,7 +16,7 @@ test('parallel', function () use ($run) { expect($run('--exclude-group=integration')) - ->toContain('Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 17 todos, 19 skipped, 1085 passed (2624 assertions)') + ->toContain('Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 17 todos, 19 skipped, 1086 passed (2625 assertions)') ->toContain('Parallel: 3 processes'); })->skipOnWindows();