Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: uses beforeAll not being called since 3.0.4 #1322

Open
wants to merge 3 commits into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Concerns/Testable.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ public function __construct(string $name)
self::$__latestPrs = $method->prs;
$this->__describing = $method->describing;
$this->__test = $method->getClosure();

$method->setUp($this);
}
}

Expand Down Expand Up @@ -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')
Expand Down
5 changes: 4 additions & 1 deletion tests/.snapshots/success.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 38 todos, 33 skipped, 1153 passed (2748 assertions)
19 changes: 19 additions & 0 deletions tests/Hooks/BeforeAllTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

$_SERVER['beforeAllCalls'] = 0;

pest()->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);
});
4 changes: 3 additions & 1 deletion tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down
2 changes: 1 addition & 1 deletion tests/Visual/Parallel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down