mirror of
https://github.com/pestphp/pest.git
synced 2026-12-04 15:05:09 +01:00
f66a8e9e93
`Backtrace::backtrace()` skipped a frame when its path held `pest/src`, so a checkout of this repository in a directory with any other name, such as `pest5`, returned `src/Support/Backtrace.php` as the file of the caller and `tests/Unit/Support/Backtrace.php` failed. The frame check now compares against the directory that holds this file, which is the same directory whether Pest runs from its own checkout or from `vendor/pestphp/pest`, and the global that marked the internal test suite has no reader left. Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: Punyapal Shah <53343069+MrPunyapal@users.noreply.github.com>
95 lines
2.4 KiB
PHP
95 lines
2.4 KiB
PHP
<?php
|
|
|
|
use Tests\CustomTestCase\CustomTestCase;
|
|
use Tests\CustomTestCaseInSubFolders\SubFolder\SubFolder\CustomTestCaseInSubFolder;
|
|
|
|
error_reporting(E_ALL);
|
|
|
|
pest()->project()->github('pestphp/pest');
|
|
|
|
pest()->in('PHPUnit/CustomTestCaseInSubFolders/SubFolder/SubFolder')->use(CustomTestCaseInSubFolder::class);
|
|
|
|
pest()->in('PHPUnit/GlobPatternTests/SubFolder/*')->extend(CustomTestCase::class);
|
|
|
|
pest()->in('PHPUnit/GlobPatternTests/SubFolder2/*AsPattern.php')->use(CustomTestCase::class);
|
|
|
|
pest()->in('Visual')->group('integration');
|
|
|
|
pest()->in('Features/Tia')->group('integration', 'tia');
|
|
|
|
$_SERVER['globalHook'] = (object) ['calls' => (object) ['beforeAll' => 0, 'afterAll' => 0]];
|
|
|
|
pest()
|
|
->in('Hooks')
|
|
->beforeEach(function (): void {
|
|
$this->baz = 0;
|
|
})
|
|
->beforeAll(function (): void {
|
|
$_SERVER['globalHook']->beforeAll = 0;
|
|
})
|
|
->afterEach(function (): void {
|
|
if (! isset($this->ith)) {
|
|
return;
|
|
}
|
|
|
|
assert($this->ith === 1, 'Expected $this->ith to be 1, but got '.$this->ith);
|
|
$this->ith++;
|
|
})
|
|
->afterAll(function (): void {
|
|
$_SERVER['globalHook']->afterAll = 0;
|
|
$_SERVER['globalHook']->calls->afterAll++;
|
|
});
|
|
|
|
pest()->in('Hooks')
|
|
->beforeEach(function (): void {
|
|
expect($this)
|
|
->toHaveProperty('baz')
|
|
->and($this->baz)
|
|
->toBe(0);
|
|
|
|
$this->baz = 1;
|
|
})
|
|
->beforeAll(function (): void {
|
|
expect($_SERVER['globalHook'])
|
|
->toHaveProperty('beforeAll')
|
|
->and($_SERVER['globalHook']->beforeAll)
|
|
->toBe(0);
|
|
|
|
$_SERVER['globalHook']->beforeAll = 1;
|
|
})
|
|
->afterEach(function (): void {
|
|
if (! isset($this->ith)) {
|
|
return;
|
|
}
|
|
|
|
assert($this->ith === 2, 'Expected $this->ith to be 1, but got '.$this->ith);
|
|
$this->ith++;
|
|
})
|
|
->afterAll(function (): void {
|
|
expect($_SERVER['globalHook'])
|
|
->toHaveProperty('afterAll')
|
|
->and($_SERVER['globalHook']->afterAll)
|
|
->toBe(0);
|
|
|
|
$_SERVER['globalHook']->afterAll = 1;
|
|
});
|
|
|
|
function helper_returns_string(): string
|
|
{
|
|
return 'string';
|
|
}
|
|
|
|
dataset('dataset_in_pest_file', ['A', 'B']);
|
|
|
|
function removeAnsiEscapeSequences(string $input): ?string
|
|
{
|
|
return preg_replace(
|
|
[
|
|
'#\\x1b[[][^A-Za-z]*[A-Za-z]#',
|
|
'#\\x1b\\]8;[^\\x1b\\x07]*(?:\\x1b\\\\|\\x07)#',
|
|
],
|
|
'',
|
|
$input,
|
|
);
|
|
}
|