From 129a73388878b6ed16cb2df05104974bcabffbf2 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Sat, 4 Dec 2021 21:23:25 +0000 Subject: [PATCH] chore: re-adds removed tests --- tests/Hooks/AfterAllTest.php | 44 ++++++++++++++++++++++++++++ tests/Hooks/BeforeAllTest.php | 54 +++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) diff --git a/tests/Hooks/AfterAllTest.php b/tests/Hooks/AfterAllTest.php index b3d9bbc7..fb0726a7 100644 --- a/tests/Hooks/AfterAllTest.php +++ b/tests/Hooks/AfterAllTest.php @@ -1 +1,45 @@ afterAll(function () { + expect($_SERVER['globalHook']) + ->toHaveProperty('afterAll') + ->and($_SERVER['globalHook']->afterAll) + ->toBe(0) + ->and($_SERVER['globalHook']->calls) + ->afterAll + ->toBe(1); + + $_SERVER['globalHook']->afterAll = 1; + $_SERVER['globalHook']->calls->afterAll++; +}); + +afterAll(function () { + expect($_SERVER['globalHook']) + ->toHaveProperty('afterAll') + ->and($_SERVER['globalHook']->afterAll) + ->toBe(1) + ->and($_SERVER['globalHook']->calls) + ->afterAll + ->toBe(2); + + $_SERVER['globalHook']->afterAll = 2; + $_SERVER['globalHook']->calls->afterAll++; +}); + +test('global afterAll execution order', function () { + expect($_SERVER['globalHook']) + ->not() + ->toHaveProperty('afterAll') + ->and($_SERVER['globalHook']->calls) + ->afterAll + ->toBe(0); +}); + +it('only gets called once per file', function () { + expect($_SERVER['globalHook']) + ->not() + ->toHaveProperty('afterAll') + ->and($_SERVER['globalHook']->calls) + ->afterAll + ->toBe(0); +}); diff --git a/tests/Hooks/BeforeAllTest.php b/tests/Hooks/BeforeAllTest.php index e69de29b..4cea5faa 100644 --- a/tests/Hooks/BeforeAllTest.php +++ b/tests/Hooks/BeforeAllTest.php @@ -0,0 +1,54 @@ +calls baseline. This is because +// two other tests are executed before this one due to filename ordering. +$args = $_SERVER['argv'] ?? []; +$single = (isset($args[1]) && Str::endsWith(__FILE__, $args[1])) || ($_SERVER['PEST_PARALLEL'] ?? false); +$offset = $single ? 0 : 2; + +uses()->beforeAll(function () use ($offset) { + expect($_SERVER['globalHook']) + ->toHaveProperty('beforeAll') + ->and($_SERVER['globalHook']->beforeAll) + ->toBe(0) + ->and($_SERVER['globalHook']->calls) + ->beforeAll + ->toBe(1 + $offset); + + $_SERVER['globalHook']->beforeAll = 1; + $_SERVER['globalHook']->calls->beforeAll++; +}); + +beforeAll(function () use ($offset) { + expect($_SERVER['globalHook']) + ->toHaveProperty('beforeAll') + ->and($_SERVER['globalHook']->beforeAll) + ->toBe(1) + ->and($_SERVER['globalHook']->calls) + ->beforeAll + ->toBe(2 + $offset); + + $_SERVER['globalHook']->beforeAll = 2; + $_SERVER['globalHook']->calls->beforeAll++; +}); + +test('global beforeAll execution order', function () use ($offset) { + expect($_SERVER['globalHook']) + ->toHaveProperty('beforeAll') + ->and($_SERVER['globalHook']->beforeAll) + ->toBe(2) + ->and($_SERVER['globalHook']->calls) + ->beforeAll + ->toBe(3 + $offset); +}); + +it('only gets called once per file', function () use ($offset) { + expect($_SERVER['globalHook']) + ->beforeAll + ->toBe(2) + ->and($_SERVER['globalHook']->calls) + ->beforeAll + ->toBe(3 + $offset); +});