mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
51 lines
1.1 KiB
PHP
51 lines
1.1 KiB
PHP
<?php
|
|
|
|
$state = new stdClass;
|
|
|
|
beforeEach(function () use ($state) {
|
|
$this->state = $state;
|
|
});
|
|
|
|
afterEach(function () {
|
|
$this->state->bar = 1;
|
|
});
|
|
|
|
afterEach(function () {
|
|
unset($this->state->bar);
|
|
});
|
|
|
|
it('does not get executed before the test', function () {
|
|
expect($this->state)->not->toHaveProperty('bar');
|
|
});
|
|
|
|
it('gets executed after the test', function () {
|
|
expect($this->state)->toHaveProperty('bar');
|
|
expect($this->state->bar)->toBe(2);
|
|
});
|
|
|
|
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);
|
|
});
|
|
});
|
|
});
|