Execute all parent beforeEach and afterEach functions for each test

This commit is contained in:
jshayes
2024-10-11 23:32:45 -04:00
parent 0c57142c03
commit a6cd83665c
13 changed files with 77 additions and 22 deletions

View File

@ -27,6 +27,8 @@
PASS Tests\Features\AfterEach
✓ it does not get executed before the test
✓ it gets executed after the test
✓ outer → inner → it does not get executed before the test
✓ outer → inner → it should call all parent afterEach functions
PASS Tests\Features\Assignee
✓ it may be associated with an assignee [@nunomaduro, @taylorotwell]
@ -40,6 +42,7 @@
PASS Tests\Features\BeforeEach
✓ it gets executed before each test
✓ it gets executed before each test once again
✓ outer → inner → it should call all parent beforeEach functions
PASS Tests\Features\BeforeEachProxiesToTestCallWithExpectations
✓ runs 1
@ -1585,4 +1588,4 @@
WARN Tests\Visual\Version
- visual snapshot of help command output
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 17 todos, 28 skipped, 1096 passed (2649 assertions)
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 17 todos, 28 skipped, 1099 passed (2656 assertions)

View File

@ -26,3 +26,25 @@ it('gets executed after the test', function () {
afterEach(function () {
$this->state->bar = 2;
});
describe('outer', function () {
afterEach(function () {
$this->state->bar++;
});
describe('inner', function () {
afterEach(function () {
$this->state->bar++;
});
it('does not get executed before the test', function () {
expect($this->state)->toHaveProperty('bar');
expect($this->state->bar)->toBe(2);
});
it('should call all parent afterEach functions', function () {
expect($this->state)->toHaveProperty('bar');
expect($this->state->bar)->toBe(4);
});
});
});

View File

@ -25,3 +25,19 @@ it('gets executed before each test once again', function () {
beforeEach(function () {
$this->bar++;
});
describe('outer', function () {
beforeEach(function () {
$this->bar++;
});
describe('inner', function () {
beforeEach(function () {
$this->bar++;
});
it('should call all parent beforeEach functions', function () {
expect($this->bar)->toBe(3);
});
});
});

View File

@ -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, 1086 passed (2625 assertions)')
->toContain('Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 17 todos, 19 skipped, 1089 passed (2632 assertions)')
->toContain('Parallel: 3 processes');
})->skipOnWindows();