feat: pr and issue

This commit is contained in:
Nuno Maduro
2024-07-04 00:53:58 +01:00
parent 09ca7a1fd5
commit ee32f25485
26 changed files with 423 additions and 53 deletions

View File

@ -18,6 +18,11 @@ final class DescribeCall
*/
private static ?string $describing = null;
/**
* The describe "before each" call.
*/
private ?BeforeEachCall $currentBeforeEachCall = null;
/**
* Creates a new Pending Call.
*/
@ -43,6 +48,8 @@ final class DescribeCall
*/
public function __destruct()
{
unset($this->currentBeforeEachCall);
self::$describing = $this->description;
try {
@ -57,14 +64,18 @@ final class DescribeCall
*
* @param array<int, mixed> $arguments
*/
public function __call(string $name, array $arguments): BeforeEachCall
public function __call(string $name, array $arguments): self
{
$filename = Backtrace::file();
$beforeEachCall = new BeforeEachCall(TestSuite::getInstance(), $filename);
if (! $this->currentBeforeEachCall instanceof \Pest\PendingCalls\BeforeEachCall) {
$this->currentBeforeEachCall = new BeforeEachCall(TestSuite::getInstance(), $filename);
$beforeEachCall->describing = $this->description;
$this->currentBeforeEachCall->describing = $this->description;
}
return $beforeEachCall->{$name}(...$arguments); // @phpstan-ignore-line
$this->currentBeforeEachCall->{$name}(...$arguments); // @phpstan-ignore-line
return $this;
}
}

View File

@ -364,6 +364,48 @@ final class TestCall
return $this;
}
/**
* Associates the test with the given issue(s).
*
* @param array<int, string|int>|string|int $number
*/
public function issue(array|string|int $number): self
{
$number = is_array($number) ? $number : [$number];
$number = array_map(fn (string|int $number): int => (int) ltrim((string) $number, '#'), $number);
$this->testCaseMethod->issues = array_merge($this->testCaseMethod->issues, $number);
return $this;
}
/**
* Associates the test with the given ticket(s). (Alias for `issue`)
*
* @param array<int, string|int>|string|int $number
*/
public function ticket(array|string|int $number): self
{
return $this->issue($number);
}
/**
* Associates the test with the given pull request(s).
*
* @param array<int, string|int>|string|int $number
*/
public function pr(array|string|int $number): self
{
$number = is_array($number) ? $number : [$number];
$number = array_map(fn (string|int $number): int => (int) ltrim((string) $number, '#'), $number);
$this->testCaseMethod->prs = array_merge($this->testCaseMethod->issues, $number);
return $this;
}
/**
* Adds a note to the test.
*