From ab04aef56173a2146118fceff50360a1b0c66d64 Mon Sep 17 00:00:00 2001 From: luke Date: Wed, 11 Aug 2021 20:59:19 +0100 Subject: [PATCH] Refactors `addOutput` --- src/Actions/InteractsWithPlugins.php | 17 +++++++++++++++++ src/Console/Command.php | 12 ++---------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/Actions/InteractsWithPlugins.php b/src/Actions/InteractsWithPlugins.php index e2a512be..d8c5d376 100644 --- a/src/Actions/InteractsWithPlugins.php +++ b/src/Actions/InteractsWithPlugins.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Pest\Actions; +use Pest\Contracts\Plugins\AddsOutput; use Pest\Contracts\Plugins\HandlesArguments; use Pest\Plugin\Loader; @@ -30,4 +31,20 @@ final class InteractsWithPlugins return $argv; } + + /** + * Provides an opportunity for any plugins that want + * to provide additional output after test execution. + */ + public static function addOutput(int $result): int + { + $plugins = Loader::getPlugins(AddsOutput::class); + + /** @var AddsOutput $plugin */ + foreach ($plugins as $plugin) { + $result = $plugin->addOutput($result); + } + + return $result; + } } diff --git a/src/Console/Command.php b/src/Console/Command.php index 1ddc510f..06750381 100644 --- a/src/Console/Command.php +++ b/src/Console/Command.php @@ -6,6 +6,7 @@ namespace Pest\Console; use Pest\Actions\AddsDefaults; use Pest\Actions\AddsTests; +use Pest\Actions\InteractsWithPlugins; use Pest\Actions\LoadStructure; use Pest\Actions\ValidatesConfiguration; use Pest\Contracts\Plugins\AddsOutput; @@ -114,16 +115,7 @@ final class Command extends BaseCommand LoadStructure::in($this->testSuite->rootPath); $result = parent::run($argv, false); - - /* - * Let's call all plugins that want to add output after test execution - */ - $plugins = Loader::getPlugins(AddsOutput::class); - - /** @var AddsOutput $plugin */ - foreach ($plugins as $plugin) { - $result = $plugin->addOutput($result); - } + $result = InteractsWithPlugins::addOutput($result); exit($result); }