mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
Adds assignees
This commit is contained in:
@ -41,22 +41,32 @@ final class Events
|
||||
renderUsing(self::$output);
|
||||
|
||||
[
|
||||
'assignees' => $assignees,
|
||||
'issues' => $issues,
|
||||
'prs' => $prs,
|
||||
] = $context;
|
||||
|
||||
if ((($link = Context::getInstance()->issues) !== '' && ($link = Context::getInstance()->issues) !== '0')) {
|
||||
if (($link = Context::getInstance()->issues) !== '') {
|
||||
$issuesDescription = array_map(fn (int $issue): string => sprintf('<a href="%s">#%s</a>', sprintf($link, $issue), $issue), $issues);
|
||||
}
|
||||
|
||||
if ((($link = Context::getInstance()->prs) !== '' && ($link = Context::getInstance()->prs) !== '0')) {
|
||||
if (($link = Context::getInstance()->prs) !== '') {
|
||||
$prsDescription = array_map(fn (int $pr): string => sprintf('<a href="%s">#%s</a>', sprintf($link, $pr), $pr), $prs);
|
||||
}
|
||||
|
||||
if (count($issues) > 0 || count($prs) > 0) {
|
||||
if (($link = Context::getInstance()->assignees) !== '' && count($assignees) > 0) {
|
||||
$assigneesDescription = array_map(fn (string $assignee): string => sprintf(
|
||||
'<a href="%s">@%s</a>',
|
||||
sprintf($link, $assignee),
|
||||
$assignee,
|
||||
), $assignees);
|
||||
}
|
||||
|
||||
if (count($assignees) > 0 || count($issues) > 0 || count($prs) > 0) {
|
||||
$description .= ' '.implode(', ', array_merge(
|
||||
$issuesDescription ?? [],
|
||||
$prsDescription ?? [],
|
||||
isset($assigneesDescription) ? ['['.implode(', ', $assigneesDescription).']'] : [],
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@ -34,6 +34,11 @@ trait Testable
|
||||
*/
|
||||
private static string $__latestDescription;
|
||||
|
||||
/**
|
||||
* The test's assignees.
|
||||
*/
|
||||
private static array $__latestAssignees = [];
|
||||
|
||||
/**
|
||||
* The test's notes.
|
||||
*/
|
||||
@ -105,6 +110,7 @@ trait Testable
|
||||
if ($test->hasMethod($name)) {
|
||||
$method = $test->getMethod($name);
|
||||
$this->__description = self::$__latestDescription = $method->description;
|
||||
self::$__latestAssignees = $method->assignees;
|
||||
self::$__latestNotes = $method->notes;
|
||||
self::$__latestIssues = $method->issues;
|
||||
self::$__latestPrs = $method->prs;
|
||||
@ -258,6 +264,7 @@ trait Testable
|
||||
}
|
||||
|
||||
$this->__description = self::$__latestDescription = $description;
|
||||
self::$__latestAssignees = $method->assignees;
|
||||
self::$__latestNotes = $method->notes;
|
||||
self::$__latestIssues = $method->issues;
|
||||
self::$__latestPrs = $method->prs;
|
||||
@ -449,6 +456,7 @@ trait Testable
|
||||
public static function getPrintableContext(): array
|
||||
{
|
||||
return [
|
||||
'assignees' => self::$__latestAssignees,
|
||||
'issues' => self::$__latestIssues,
|
||||
'prs' => self::$__latestPrs,
|
||||
'notes' => self::$__latestNotes,
|
||||
|
||||
@ -9,6 +9,13 @@ namespace Pest\Configuration;
|
||||
*/
|
||||
final class Context
|
||||
{
|
||||
/**
|
||||
* The assignees link.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public string $assignees = '';
|
||||
|
||||
/**
|
||||
* The issues link.
|
||||
*
|
||||
@ -44,6 +51,8 @@ final class Context
|
||||
$this->issues = "https://github.com/{$project}/issues/%s";
|
||||
$this->prs = "https://github.com/{$project}/pull/%s";
|
||||
|
||||
$this->assignees = 'https://github.com/%s';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -55,6 +64,8 @@ final class Context
|
||||
$this->issues = "https://gitlab.com/{$project}/issues/%s";
|
||||
$this->prs = "https://gitlab.com/{$project}/merge_requests/%s";
|
||||
|
||||
$this->assignees = 'https://gitlab.com/%s';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -66,6 +77,8 @@ final class Context
|
||||
$this->issues = 'https://bitbucket.org/{$project}/issues/%s';
|
||||
$this->prs = "https://bitbucket.org/{$project}/pull-requests/%s";
|
||||
|
||||
$this->assignees = 'https://bitbucket.org/%s';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -76,17 +89,21 @@ final class Context
|
||||
{
|
||||
$this->issues = "https://{$namespace}.atlassian.net/browse/{$project}-%s";
|
||||
|
||||
$this->assignees = "https://{$namespace}.atlassian.net/secure/ViewProfile?name=%s";
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the test context to custom.
|
||||
*/
|
||||
public function using(string $issues, string $prs): self
|
||||
public function using(string $issues, string $prs, string $assignees): self
|
||||
{
|
||||
$this->issues = $issues;
|
||||
$this->prs = $prs;
|
||||
|
||||
$this->assignees = $assignees;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,6 +56,13 @@ final class TestCaseMethodFactory
|
||||
*/
|
||||
public array $issues = [];
|
||||
|
||||
/**
|
||||
* The test assignees.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
public array $assignees = [];
|
||||
|
||||
/**
|
||||
* The associated PRs numbers.
|
||||
*
|
||||
|
||||
@ -390,6 +390,18 @@ final class TestCall
|
||||
return $this->issue($number);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the test assignee(s).
|
||||
*/
|
||||
public function assignee(array|string $assignee): self
|
||||
{
|
||||
$assignees = is_array($assignee) ? $assignee : [$assignee];
|
||||
|
||||
$this->testCaseMethod->assignees = array_unique(array_merge($this->testCaseMethod->assignees, $assignees));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Associates the test with the given pull request(s).
|
||||
*
|
||||
@ -401,7 +413,7 @@ final class TestCall
|
||||
|
||||
$number = array_map(fn (string|int $number): int => (int) ltrim((string) $number, '#'), $number);
|
||||
|
||||
$this->testCaseMethod->prs = array_merge($this->testCaseMethod->issues, $number);
|
||||
$this->testCaseMethod->prs = array_unique(array_merge($this->testCaseMethod->issues, $number));
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -415,7 +427,7 @@ final class TestCall
|
||||
{
|
||||
$notes = is_array($note) ? $note : [$note];
|
||||
|
||||
$this->testCaseMethod->notes = array_merge($this->testCaseMethod->notes, $notes);
|
||||
$this->testCaseMethod->notes = array_unique(array_merge($this->testCaseMethod->notes, $notes));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
27
src/TestCaseMethodFilters/AssigneeTestCaseFilter.php
Normal file
27
src/TestCaseMethodFilters/AssigneeTestCaseFilter.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\TestCaseMethodFilters;
|
||||
|
||||
use Pest\Contracts\TestCaseMethodFilter;
|
||||
use Pest\Factories\TestCaseMethodFactory;
|
||||
|
||||
final readonly class AssigneeTestCaseFilter implements TestCaseMethodFilter
|
||||
{
|
||||
/**
|
||||
* Create a new filter instance.
|
||||
*/
|
||||
public function __construct(private string $assignee)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the test case methods.
|
||||
*/
|
||||
public function accept(TestCaseMethodFactory $factory): bool
|
||||
{
|
||||
return array_filter($factory->assignees, fn ($assignee): bool => str_starts_with($assignee, $this->assignee)) !== [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user