diff --git a/src/Concerns/Testable.php b/src/Concerns/Testable.php index 37d3b175..a3f4d71d 100644 --- a/src/Concerns/Testable.php +++ b/src/Concerns/Testable.php @@ -119,6 +119,8 @@ public function __construct(string $name) self::$__latestPrs = $method->prs; $this->__describing = $method->describing; $this->__test = $method->getClosure(); + + $method->setUp($this); } } @@ -242,8 +244,6 @@ protected function setUp(...$arguments): void $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') diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 90b1b085..93c0ebbb 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -1425,6 +1425,9 @@ ✓ nested → nested afterEach execution order ✓ global afterEach execution order + PASS Tests\Hooks\BeforeAllTest + ✓ beforeAll is called + PASS Tests\Hooks\BeforeEachTest ✓ global beforeEach execution order @@ -1708,4 +1711,4 @@ WARN Tests\Visual\Version - visual snapshot of help command output - Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 38 todos, 33 skipped, 1152 passed (2744 assertions) \ No newline at end of file + Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 38 todos, 33 skipped, 1153 passed (2748 assertions) diff --git a/tests/Hooks/BeforeAllTest.php b/tests/Hooks/BeforeAllTest.php new file mode 100644 index 00000000..553390d3 --- /dev/null +++ b/tests/Hooks/BeforeAllTest.php @@ -0,0 +1,19 @@ +beforeAll(function () { + $_SERVER['beforeAllCalls']++; + + expect($_SERVER['beforeAllCalls'])->toBe(1); +}); + +beforeAll(function () { + $_SERVER['beforeAllCalls']++; + + expect($_SERVER['beforeAllCalls'])->toBe(2); +}); + +test('beforeAll is called', function () { + expect($_SERVER['beforeAllCalls'])->toBe(2); +}); diff --git a/tests/Pest.php b/tests/Pest.php index a938fc7e..f09f579d 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -73,7 +73,9 @@ expect($_SERVER['globalHook']) ->toHaveProperty('afterAll') ->and($_SERVER['globalHook']->afterAll) - ->toBe(0); + ->toBe(0) + ->and($_SERVER['globalHook']->beforeAll) + ->toBe(1); $_SERVER['globalHook']->afterAll = 1; }); diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index 036f51d7..f2303f45 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -16,7 +16,7 @@ test('parallel', function () use ($run) { expect($run('--exclude-group=integration')) - ->toContain('Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 38 todos, 24 skipped, 1142 passed (2720 assertions)') + ->toContain('Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 38 todos, 24 skipped, 1143 passed (2724 assertions)') ->toContain('Parallel: 3 processes'); })->skipOnWindows();