Skip to content

Commit 0c57142

Browse files
committed
Fix an issue where a describe block will prevent a beforeEach call from executing
1 parent 3f65af9 commit 0c57142

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

src/PendingCalls/DescribeCall.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ final class DescribeCall
1515
{
1616
/**
1717
* The current describe call.
18+
*
19+
* @var string[]
1820
*/
19-
private static ?string $describing = null;
21+
private static array $describing = [];
2022

2123
/**
2224
* The describe "before each" call.
@@ -40,7 +42,7 @@ public function __construct(
4042
*/
4143
public static function describing(): ?string
4244
{
43-
return self::$describing;
45+
return self::$describing[count(self::$describing) - 1] ?? null;
4446
}
4547

4648
/**
@@ -50,12 +52,12 @@ public function __destruct()
5052
{
5153
unset($this->currentBeforeEachCall);
5254

53-
self::$describing = $this->description;
55+
self::$describing[] = $this->description;
5456

5557
try {
5658
($this->tests)();
5759
} finally {
58-
self::$describing = null;
60+
array_pop(self::$describing);
5961
}
6062
}
6163

tests/.snapshots/success.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@
215215
✓ depends on describe → bar
216216
✓ depends on describe using with → foo with (3)
217217
✓ depends on describe using with → bar with (3)
218+
✓ with test after describe → it should run the before each
218219

219220
PASS Tests\Features\DescriptionLess
220221
✓ get 'foo'
@@ -1584,4 +1585,4 @@
15841585
WARN Tests\Visual\Version
15851586
- visual snapshot of help command output
15861587

1587-
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 17 todos, 28 skipped, 1095 passed (2648 assertions)
1588+
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 17 todos, 28 skipped, 1096 passed (2649 assertions)

tests/Features/Describe.php

+12
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,15 @@
9696
expect($foo + $foo)->toBe(6);
9797
})->depends('foo');
9898
})->with([3]);
99+
100+
describe('with test after describe', function () {
101+
beforeEach(function () {
102+
$this->count++;
103+
});
104+
105+
describe('foo', function () {});
106+
107+
it('should run the before each', function () {
108+
expect($this->count)->toBe(2);
109+
});
110+
});

tests/Visual/Parallel.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
test('parallel', function () use ($run) {
1818
expect($run('--exclude-group=integration'))
19-
->toContain('Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 17 todos, 19 skipped, 1085 passed (2624 assertions)')
19+
->toContain('Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 17 todos, 19 skipped, 1086 passed (2625 assertions)')
2020
->toContain('Parallel: 3 processes');
2121
})->skipOnWindows();
2222

0 commit comments

Comments
 (0)