From 584a7ac8a5fcce4ec5147805b7564f82a610e919 Mon Sep 17 00:00:00 2001 From: jordanbrauer <18744334+jordanbrauer@users.noreply.github.com> Date: Wed, 7 Apr 2021 10:52:49 -0500 Subject: [PATCH] test: add cases for global before/after all hooks --- tests/Hooks/AfterAllTest.php | 23 ++++++++++++++++++++--- tests/Hooks/BeforeAllTest.php | 24 +++++++++++++++++++++--- tests/Pest.php | 14 ++++++++------ 3 files changed, 49 insertions(+), 12 deletions(-) diff --git a/tests/Hooks/AfterAllTest.php b/tests/Hooks/AfterAllTest.php index ae8d61f4..a34a5847 100644 --- a/tests/Hooks/AfterAllTest.php +++ b/tests/Hooks/AfterAllTest.php @@ -1,10 +1,27 @@ afterAll(function () { +global $globalHook; + +uses()->afterAll(function () use ($globalHook) { + expect($globalHook) + ->toHaveProperty('afterAll') + ->and($globalHook->afterAll) + ->toBe(0); + + $globalHook->afterAll = 1; }); -afterAll(function () { +afterAll(function () use ($globalHook) { + expect($globalHook) + ->toHaveProperty('afterAll') + ->and($globalHook->afterAll) + ->toBe(1); + + $globalHook->afterAll = 2; }); -test('global afterAll execution order', function () { +test('global afterAll execution order', function () use ($globalHook) { + expect($globalHook) + ->not() + ->toHaveProperty('afterAll'); }); diff --git a/tests/Hooks/BeforeAllTest.php b/tests/Hooks/BeforeAllTest.php index 0eb27eb9..11c996c5 100644 --- a/tests/Hooks/BeforeAllTest.php +++ b/tests/Hooks/BeforeAllTest.php @@ -1,10 +1,28 @@ beforeAll(function () { +global $globalHook; + +uses()->beforeAll(function () use ($globalHook) { + expect($globalHook) + ->toHaveProperty('beforeAll') + ->and($globalHook->beforeAll) + ->toBe(0); + + $globalHook->beforeAll = 1; }); -beforeAll(function () { +beforeAll(function () use ($globalHook) { + expect($globalHook) + ->toHaveProperty('beforeAll') + ->and($globalHook->beforeAll) + ->toBe(1); + + $globalHook->beforeAll = 2; }); -test('global beforeAll execution order', function () { +test('global beforeAll execution order', function () use ($globalHook) { + expect($globalHook) + ->toHaveProperty('beforeAll') + ->and($globalHook->beforeAll) + ->toBe(2); }); diff --git a/tests/Pest.php b/tests/Pest.php index 795d906a..a8cd868d 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -2,17 +2,19 @@ uses()->group('integration')->in('Visual'); +$globalHook = (object) []; // NOTE: global test value container to be mutated and checked across files, as needed + uses() ->beforeEach(function () { $this->baz = 0; }) - // ->beforeAll(function () { - // dump(0); - // }) + ->beforeAll(function () use ($globalHook) { + $globalHook->beforeAll = 0; + }) ->afterEach(function () { $this->ith = 0; }) - // ->afterAll(function () { - // dump(0); - // }) + ->afterAll(function () use ($globalHook) { + $globalHook->afterAll = 0; + }) ->in('Hooks');