diff --git a/composer.json b/composer.json
index 47aa874c..76810632 100644
--- a/composer.json
+++ b/composer.json
@@ -19,7 +19,7 @@
"require": {
"php": "^8.2.0",
"brianium/paratest": "^7.5.0",
- "nunomaduro/collision": "^8.3.0",
+ "nunomaduro/collision": "^8.4.0",
"nunomaduro/termwind": "^2.0.1",
"pestphp/pest-plugin": "^3.0.0",
"pestphp/pest-plugin-arch": "^3.0.0",
diff --git a/src/Collision/Events.php b/src/Collision/Events.php
new file mode 100644
index 00000000..4810167d
--- /dev/null
+++ b/src/Collision/Events.php
@@ -0,0 +1,90 @@
+context) === []) {
+ return $description;
+ }
+
+ renderUsing(self::$output);
+
+ [
+ 'issues' => $issues,
+ 'prs' => $prs,
+ ] = $context;
+
+ if ((($link = Context::getInstance()->issues) !== '' && ($link = Context::getInstance()->issues) !== '0')) {
+ $issuesDescription = array_map(fn (int $issue): string => sprintf('#%s', sprintf($link, $issue), $issue), $issues);
+ }
+
+ if ((($link = Context::getInstance()->prs) !== '' && ($link = Context::getInstance()->prs) !== '0')) {
+ $prsDescription = array_map(fn (int $pr): string => sprintf('#%s', sprintf($link, $pr), $pr), $prs);
+ }
+
+ if (count($issues) > 0 || count($prs) > 0) {
+ $description .= ' '.implode(', ', array_merge(
+ $issuesDescription ?? [],
+ $prsDescription ?? [],
+ ));
+ }
+
+ return $description;
+ }
+
+ /**
+ * Fires after the test method description is printed.
+ */
+ public static function afterTestMethodDescription(TestResult $result): void
+ {
+ if (($context = $result->context) === []) {
+ return;
+ }
+
+ renderUsing(self::$output);
+
+ [
+ 'notes' => $notes,
+ ] = $context;
+
+ foreach ($notes as $note) {
+ render(sprintf(<<<'HTML'
+
+ // %s
+
+ HTML, $note,
+ ));
+ }
+ }
+}
diff --git a/src/Concerns/Testable.php b/src/Concerns/Testable.php
index f2090169..4db2887d 100644
--- a/src/Concerns/Testable.php
+++ b/src/Concerns/Testable.php
@@ -444,26 +444,14 @@ trait Testable
}
/**
- * The latest printable test case notes.
+ * The printable test case method context.
*/
- public static function getPrintableTestCaseMethodNotes(): array
+ public static function getPrintableContext(): array
{
- return self::$__latestNotes;
- }
-
- /**
- * The latest printable test case issues.
- */
- public static function getPrintableTestCaseMethodIssues(): array
- {
- return self::$__latestIssues;
- }
-
- /**
- * The latest printable test case PRs.
- */
- public static function getPrintableTestCaseMethodPrs(): array
- {
- return self::$__latestPrs;
+ return [
+ 'issues' => self::$__latestIssues,
+ 'prs' => self::$__latestPrs,
+ 'notes' => self::$__latestNotes,
+ ];
}
}
diff --git a/src/Configuration.php b/src/Configuration.php
index 6eed2d05..556e8432 100644
--- a/src/Configuration.php
+++ b/src/Configuration.php
@@ -73,6 +73,6 @@ final class Configuration
*/
public function context(): Configuration\Context
{
- return new Configuration\Context;
+ return Configuration\Context::getInstance();
}
}
diff --git a/src/Configuration/Context.php b/src/Configuration/Context.php
index 0bec19ff..97ae4189 100644
--- a/src/Configuration/Context.php
+++ b/src/Configuration/Context.php
@@ -4,20 +4,45 @@ declare(strict_types=1);
namespace Pest\Configuration;
-use NunoMaduro\Collision\Adapters\Phpunit\Printers\DefaultPrinter;
-
/**
* @internal
*/
-final readonly class Context
+final class Context
{
+ /**
+ * The issues link.
+ *
+ * @internal
+ */
+ public string $issues = '';
+
+ /**
+ * The PRs link.
+ *
+ * @internal
+ */
+ public string $prs = '';
+
+ /**
+ * The singleton instance.
+ */
+ private static ?self $instance = null;
+
+ /**
+ * Creates a new instance of the context.
+ */
+ public static function getInstance(): self
+ {
+ return self::$instance ??= new self;
+ }
+
/**
* Sets the test context to GitHub.
*/
public function github(string $project): self
{
- DefaultPrinter::linkIssuesWith("https://github.com/{$project}/issues/%s");
- DefaultPrinter::linkPrsWith("https://github.com/{$project}/pull/%s");
+ $this->issues = "https://github.com/{$project}/issues/%s";
+ $this->prs = "https://github.com/{$project}/pull/%s";
return $this;
}
@@ -27,8 +52,8 @@ final readonly class Context
*/
public function gitlab(string $project): self
{
- DefaultPrinter::linkIssuesWith("https://gitlab.com/{$project}/issues/%s");
- DefaultPrinter::linkPrsWith("https://gitlab.com/{$project}/merge_requests/%s");
+ $this->issues = "https://gitlab.com/{$project}/issues/%s";
+ $this->prs = "https://gitlab.com/{$project}/merge_requests/%s";
return $this;
}
@@ -38,8 +63,8 @@ final readonly class Context
*/
public function bitbucket(string $project): self
{
- DefaultPrinter::linkIssuesWith('https://bitbucket.org/{$project}/issues/%s');
- DefaultPrinter::linkPrsWith("https://bitbucket.org/{$project}/pull-requests/%s");
+ $this->issues = 'https://bitbucket.org/{$project}/issues/%s';
+ $this->prs = "https://bitbucket.org/{$project}/pull-requests/%s";
return $this;
}
@@ -49,7 +74,7 @@ final readonly class Context
*/
public function jira(string $namespace, string $project): self
{
- DefaultPrinter::linkIssuesWith("https://{$namespace}.atlassian.net/browse/{$project}-%s");
+ $this->issues = "https://{$namespace}.atlassian.net/browse/{$project}-%s";
return $this;
}
@@ -59,8 +84,8 @@ final readonly class Context
*/
public function using(string $issues, string $prs): self
{
- DefaultPrinter::linkIssuesWith($issues);
- DefaultPrinter::linkPrsWith($prs);
+ $this->issues = $issues;
+ $this->prs = $prs;
return $this;
}
diff --git a/src/TestCaseMethodFilters/NotesTestCaseFilter.php b/src/TestCaseMethodFilters/NotesTestCaseFilter.php
index 592fc600..6aafc974 100644
--- a/src/TestCaseMethodFilters/NotesTestCaseFilter.php
+++ b/src/TestCaseMethodFilters/NotesTestCaseFilter.php
@@ -9,6 +9,9 @@ use Pest\Factories\TestCaseMethodFactory;
final readonly class NotesTestCaseFilter implements TestCaseMethodFilter
{
+ /**
+ * Filter the test case methods.
+ */
public function accept(TestCaseMethodFactory $factory): bool
{
return $factory->notes !== [];