mirror of
https://github.com/pestphp/pest.git
synced 2026-03-05 23:37:22 +01:00
Fix an issue where a describe block will prevent a beforeEach call from executing
This commit is contained in:
@ -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 @@ final class DescribeCall
|
||||
*/
|
||||
public static function describing(): ?string
|
||||
{
|
||||
return self::$describing;
|
||||
return self::$describing[count(self::$describing) - 1] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -50,12 +52,12 @@ final class DescribeCall
|
||||
{
|
||||
unset($this->currentBeforeEachCall);
|
||||
|
||||
self::$describing = $this->description;
|
||||
self::$describing[] = $this->description;
|
||||
|
||||
try {
|
||||
($this->tests)();
|
||||
} finally {
|
||||
self::$describing = null;
|
||||
array_pop(self::$describing);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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)
|
||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 17 todos, 28 skipped, 1096 passed (2649 assertions)
|
||||
@ -96,3 +96,15 @@ describe('depends on describe using with', function () {
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
@ -16,7 +16,7 @@ $run = function () {
|
||||
|
||||
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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user