Fix an issue where beforeEach/afterEach functions were called on other describe blocks with the same name

This commit is contained in:
jshayes
2024-10-12 01:06:16 -04:00
parent 709ecb1ba2
commit b5b8fab09b
17 changed files with 1443 additions and 86 deletions

View File

@ -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 = [];

View File

@ -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 = [];
}

View File

@ -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
{

View 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;
}
}

View File

@ -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
{