mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
Fix an issue where beforeEach/afterEach functions were called on other describe blocks with the same name
This commit is contained in:
@ -32,7 +32,7 @@ final class TestCaseMethodFactory
|
||||
/**
|
||||
* The test's describing, if any.
|
||||
*
|
||||
* @var array<int, string>
|
||||
* @var array<int, \Pest\Support\Description>
|
||||
*/
|
||||
public array $describing = [];
|
||||
|
||||
|
||||
@ -12,14 +12,14 @@ trait Describable
|
||||
/**
|
||||
* Note: this is property is not used; however, it gets added automatically by rector php.
|
||||
*
|
||||
* @var array<int, string>
|
||||
* @var array<int, \Pest\Support\Description>
|
||||
*/
|
||||
public array $__describing;
|
||||
|
||||
/**
|
||||
* The describing of the test case.
|
||||
*
|
||||
* @var array<int, string>
|
||||
* @var array<int, \Pest\Support\Description>
|
||||
*/
|
||||
public array $describing = [];
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ namespace Pest\PendingCalls;
|
||||
|
||||
use Closure;
|
||||
use Pest\Support\Backtrace;
|
||||
use Pest\Support\Description;
|
||||
use Pest\TestSuite;
|
||||
|
||||
/**
|
||||
@ -16,7 +17,7 @@ final class DescribeCall
|
||||
/**
|
||||
* The current describe call.
|
||||
*
|
||||
* @var array<int, string>
|
||||
* @var array<int, Description>
|
||||
*/
|
||||
private static array $describing = [];
|
||||
|
||||
@ -25,22 +26,27 @@ final class DescribeCall
|
||||
*/
|
||||
private ?BeforeEachCall $currentBeforeEachCall = null;
|
||||
|
||||
/**
|
||||
* The unique description for this describe block
|
||||
*/
|
||||
private readonly Description $description;
|
||||
|
||||
/**
|
||||
* Creates a new Pending Call.
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly TestSuite $testSuite,
|
||||
public readonly string $filename,
|
||||
public readonly string $description,
|
||||
string $description,
|
||||
public readonly Closure $tests
|
||||
) {
|
||||
//
|
||||
$this->description = new Description($description);
|
||||
}
|
||||
|
||||
/**
|
||||
* What is the current describing.
|
||||
*
|
||||
* @return array<int, string>
|
||||
* @return array<int, Description>
|
||||
*/
|
||||
public static function describing(): array
|
||||
{
|
||||
|
||||
15
src/Support/Description.php
Normal file
15
src/Support/Description.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Support;
|
||||
|
||||
final readonly class Description implements \Stringable
|
||||
{
|
||||
public function __construct(private string $description) {}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
}
|
||||
@ -104,7 +104,7 @@ final class Str
|
||||
/**
|
||||
* Creates a describe block as `$describeDescription` → `$testDescription` format.
|
||||
*
|
||||
* @param array<int, string> $describeDescriptions
|
||||
* @param array<int, Description> $describeDescriptions
|
||||
*/
|
||||
public static function describe(array $describeDescriptions, string $testDescription): string
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user