Skip to content

Commit

Permalink
Fix an issue where a describe block will prevent a beforeEach call fr…
Browse files Browse the repository at this point in the history
…om executing
  • Loading branch information
jshayes committed Oct 12, 2024
1 parent 3f65af9 commit 0c57142
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/PendingCalls/DescribeCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -40,7 +42,7 @@ public function __construct(
*/
public static function describing(): ?string
{
return self::$describing;
return self::$describing[count(self::$describing) - 1] ?? null;
}

/**
Expand All @@ -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);
}
}

Expand Down
3 changes: 2 additions & 1 deletion tests/.snapshots/success.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 17 todos, 28 skipped, 1096 passed (2649 assertions)
12 changes: 12 additions & 0 deletions tests/Features/Describe.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
2 changes: 1 addition & 1 deletion tests/Visual/Parallel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 0c57142

Please sign in to comment.