mirror of
https://github.com/pestphp/pest.git
synced 2026-03-05 23:37:22 +01:00
fix: before all
This commit is contained in:
@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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)
|
||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 38 todos, 33 skipped, 1157 passed (2766 assertions)
|
||||
16
tests/Hooks/BeforeAllTest.php
Normal file
16
tests/Hooks/BeforeAllTest.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
pest()->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);
|
||||
});
|
||||
@ -29,7 +29,6 @@ pest()
|
||||
})
|
||||
->beforeAll(function () {
|
||||
$_SERVER['globalHook']->beforeAll = 0;
|
||||
$_SERVER['globalHook']->calls->beforeAll++;
|
||||
})
|
||||
->afterEach(function () {
|
||||
if (! isset($this->ith)) {
|
||||
|
||||
@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user