From 53333b56abb6f4cdf5a274c84671fd7ec584ea66 Mon Sep 17 00:00:00 2001 From: jordanbrauer <18744334+jordanbrauer@users.noreply.github.com> Date: Tue, 6 Apr 2021 19:26:42 -0500 Subject: [PATCH] test: adding tests for beforeEach and afterEach + empty tests for *All --- tests/Hooks/AfterAllTest.php | 11 +++++++++++ tests/Hooks/AfterEachTest.php | 24 ++++++++++++++++++++++++ tests/Hooks/BeforeAllTest.php | 11 +++++++++++ tests/Hooks/BeforeEachTest.php | 24 ++++++++++++++++++++---- tests/Pest.php | 19 ++++++++++++++++--- 5 files changed, 82 insertions(+), 7 deletions(-) create mode 100644 tests/Hooks/AfterAllTest.php create mode 100644 tests/Hooks/AfterEachTest.php create mode 100644 tests/Hooks/BeforeAllTest.php diff --git a/tests/Hooks/AfterAllTest.php b/tests/Hooks/AfterAllTest.php new file mode 100644 index 00000000..746ed758 --- /dev/null +++ b/tests/Hooks/AfterAllTest.php @@ -0,0 +1,11 @@ +afterAll(function () { +}); + +afterAll(function () { +}); + +test('global afterAll execution order', function () { +}); + diff --git a/tests/Hooks/AfterEachTest.php b/tests/Hooks/AfterEachTest.php new file mode 100644 index 00000000..1eea05dc --- /dev/null +++ b/tests/Hooks/AfterEachTest.php @@ -0,0 +1,24 @@ +afterEach(function () { + expect($this) + ->toHaveProperty('ith') + ->and($this->ith) + ->toBe(0); + + $this->ith = 1; +}); + +afterEach(function () { + expect($this) + ->toHaveProperty('ith') + ->and($this->ith) + ->toBe(1); +}); + +test('global afterEach execution order', function () { + expect($this) + ->not() + ->toHaveProperty('ith'); +}); + diff --git a/tests/Hooks/BeforeAllTest.php b/tests/Hooks/BeforeAllTest.php new file mode 100644 index 00000000..4c38b9b7 --- /dev/null +++ b/tests/Hooks/BeforeAllTest.php @@ -0,0 +1,11 @@ +beforeAll(function () { +}); + +beforeAll(function () { +}); + +test('global beforeAll execution order', function () { +}); + diff --git a/tests/Hooks/BeforeEachTest.php b/tests/Hooks/BeforeEachTest.php index 199d6162..e11a885b 100644 --- a/tests/Hooks/BeforeEachTest.php +++ b/tests/Hooks/BeforeEachTest.php @@ -1,11 +1,27 @@ baz)->toBe(1); // set from Pest.php global/shared hook +uses()->beforeEach(function () { + expect($this) + ->toHaveProperty('baz') + ->and($this->baz) + ->toBe(0); + + $this->baz = 1; +}); + +beforeEach(function () { + expect($this) + ->toHaveProperty('baz') + ->and($this->baz) + ->toBe(1); $this->baz = 2; }); -test('global before each', function (): void { - expect($this->baz)->toBe(2); +test('global beforeEach execution order', function () { + expect($this) + ->toHaveProperty('baz') + ->and($this->baz) + ->toBe(2); }); + diff --git a/tests/Pest.php b/tests/Pest.php index e2d51397..9c210e73 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -1,6 +1,19 @@ group('integration')->in('Visual'); -uses()->beforeEach(function (): void { - $this->baz = 1; -})->in('Hooks'); + +uses() + ->beforeEach(function () { + $this->baz = 0; + }) + // ->beforeAll(function () { + // dump(0); + // }) + ->afterEach(function () { + $this->ith = 0; + }) + // ->afterAll(function () { + // dump(0); + // }) + ->in('Hooks'); +