diff --git a/overrides/Event/Value/ThrowableBuilder.php b/overrides/Event/Value/ThrowableBuilder.php index 21d428e9..d446d03c 100644 --- a/overrides/Event/Value/ThrowableBuilder.php +++ b/overrides/Event/Value/ThrowableBuilder.php @@ -52,6 +52,8 @@ use PHPUnit\Util\Filter; use PHPUnit\Util\ThrowableToStringMapper; /** + * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit + * * @internal This class is not covered by the backward compatibility promise for PHPUnit */ final readonly class ThrowableBuilder @@ -82,7 +84,7 @@ final readonly class ThrowableBuilder $t->getMessage(), ThrowableToStringMapper::map($t), $trace, - $previous + $previous, ); } } diff --git a/src/Concerns/Testable.php b/src/Concerns/Testable.php index 326115ea..767a7c69 100644 --- a/src/Concerns/Testable.php +++ b/src/Concerns/Testable.php @@ -6,6 +6,7 @@ namespace Pest\Concerns; use Closure; use Pest\Exceptions\DatasetArgumentsMismatch; +use Pest\Panic; use Pest\Preset; use Pest\Support\ChainableClosure; use Pest\Support\ExceptionTrace; @@ -194,7 +195,11 @@ trait Testable $beforeAll = ChainableClosure::boundStatically(self::$__beforeAll, $beforeAll); } - call_user_func(Closure::bind($beforeAll, null, self::class)); + try { + call_user_func(Closure::bind($beforeAll, null, self::class)); + } catch (Throwable $e) { + Panic::with($e); + } } /** @@ -222,8 +227,6 @@ trait Testable $method = TestSuite::getInstance()->tests->get(self::$__filename)->getMethod($this->name()); - $method->setUp($this); - $description = $method->description; if ($this->dataName()) { $description = str_contains((string) $description, ':dataset') @@ -287,6 +290,8 @@ trait Testable self::$__latestPrs = $method->prs; $this->__describing = $method->describing; $this->__test = $method->getClosure(); + + $method->setUp($this); } } diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index ace3b04f..a1638158 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -1453,6 +1453,11 @@ ✓ nested → nested afterEach execution order ✓ global afterEach execution order + PASS Tests\Hooks\BeforeAllTest + ✓ it gets called before all tests 1 @ repetition 1 of 2 + ✓ it gets called before all tests 1 @ repetition 2 of 2 + ✓ it gets called before all tests 2 + PASS Tests\Hooks\BeforeEachTest ✓ global beforeEach execution order @@ -1726,4 +1731,4 @@ WARN Tests\Visual\Version - visual snapshot of help command output - Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 38 todos, 33 skipped, 1154 passed (2754 assertions) \ No newline at end of file + Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 38 todos, 33 skipped, 1157 passed (2766 assertions) \ No newline at end of file diff --git a/tests/Hooks/BeforeAllTest.php b/tests/Hooks/BeforeAllTest.php new file mode 100644 index 00000000..d411d263 --- /dev/null +++ b/tests/Hooks/BeforeAllTest.php @@ -0,0 +1,16 @@ +beforeAll(function () { + expect($_SERVER['globalHook']->calls->beforeAll) + ->toBe(0); + + $_SERVER['globalHook']->calls->beforeAll++; +}); + +it('gets called before all tests 1', function () { + expect($_SERVER['globalHook']->calls->beforeAll)->toBe(1); +})->repeat(2); + +it('gets called before all tests 2', function () { + expect($_SERVER['globalHook']->calls->beforeAll)->toBe(1); +}); diff --git a/tests/Pest.php b/tests/Pest.php index a938fc7e..e498450c 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -29,7 +29,6 @@ pest() }) ->beforeAll(function () { $_SERVER['globalHook']->beforeAll = 0; - $_SERVER['globalHook']->calls->beforeAll++; }) ->afterEach(function () { if (! isset($this->ith)) { diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index d9cdfbdd..226a01e7 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -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, 38 todos, 24 skipped, 1144 passed (2730 assertions)') + ->toContain('Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 38 todos, 24 skipped, 1147 passed (2742 assertions)') ->toContain('Parallel: 3 processes'); })->skipOnWindows();