From e24e306803425257df24d7e2f832512479bf8912 Mon Sep 17 00:00:00 2001 From: Davert Date: Fri, 2 Sep 2022 13:16:26 +0300 Subject: [PATCH 1/4] do not print extra information for empty suites --- ext/Recorder.php | 30 ++++++++++++++++++++------ src/Codeception/Subscriber/Console.php | 8 +++++++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/ext/Recorder.php b/ext/Recorder.php index 54eda50af0..493398312a 100644 --- a/ext/Recorder.php +++ b/ext/Recorder.php @@ -3,6 +3,7 @@ namespace Codeception\Extension; use Codeception\Event\StepEvent; +use Codeception\Event\SuiteEvent; use Codeception\Event\TestEvent; use Codeception\Events; use Codeception\Exception\ExtensionException; @@ -295,15 +296,22 @@ class Recorder extends \Codeception\Extension /** @var string */ private $dateFormat; - public function beforeSuite() + private $isDisabled = false; + + public function beforeSuite(SuiteEvent $e) { $this->webDriverModule = null; if (!$this->hasModule($this->config['module'])) { + $this->isDisabled = true; $this->writeln('Recorder is disabled, no available modules'); - return; } + if (!$e->getSuite()->count()) { + $this->isDisabled = true; + return; // skip for empty suites + } + $this->seed = uniqid(); $this->seeds[] = $this->seed; $this->webDriverModule = $this->getModule($this->config['module']); @@ -331,9 +339,10 @@ public function beforeSuite() public function afterSuite() { - if (!$this->webDriverModule) { + if ($this->isDisabled) { return; } + $links = ''; if (count($this->slides)) { @@ -380,7 +389,7 @@ public function afterSuite() */ public function before(TestEvent $e) { - if (!$this->webDriverModule) { + if ($this->isDisabled) { return; } $this->dir = null; @@ -407,6 +416,10 @@ public function before(TestEvent $e) */ public function cleanup(TestEvent $e) { + if ($this->isDisabled) { + return; + } + if ($this->config['delete_orphaned']) { $recordingDirectories = []; $directories = new \DirectoryIterator(codecept_output_dir()); @@ -445,9 +458,10 @@ public function cleanup(TestEvent $e) */ public function persist(TestEvent $e) { - if (!$this->webDriverModule) { + if ($this->isDisabled) { return; } + $indicatorHtml = ''; $slideHtml = ''; $testName = $this->getTestName($e); @@ -548,7 +562,11 @@ public function persist(TestEvent $e) */ public function afterStep(StepEvent $e) { - if ($this->webDriverModule === null || $this->dir === null) { + if ($this->isDisabled) { + return; + } + + if ($this->dir === null) { return; } diff --git a/src/Codeception/Subscriber/Console.php b/src/Codeception/Subscriber/Console.php index 6ef3f718a9..4066a1066f 100644 --- a/src/Codeception/Subscriber/Console.php +++ b/src/Codeception/Subscriber/Console.php @@ -125,6 +125,10 @@ public function __construct($options) // triggered for scenario based tests: cept, cest public function beforeSuite(SuiteEvent $e) { + if (!$e->getSuite()->count()) { + return; // skip for empty suites + } + $this->namespace = ""; $settings = $e->getSettings(); if (isset($settings['namespace'])) { @@ -344,6 +348,10 @@ private function printStep(Step $step) public function afterSuite(SuiteEvent $e) { + if (!$e->getSuite()->count()) { + return; // skip for empty suites + } + $this->message()->width($this->width, '-')->writeln(); $messages = Notification::all(); foreach (array_count_values($messages) as $message => $count) { From 0aa556ffd5a700eabfcc57394f381c3b16adbc3c Mon Sep 17 00:00:00 2001 From: Davert Date: Sat, 3 Sep 2022 12:02:36 +0300 Subject: [PATCH 2/4] do not start modules on empty suites --- ext/Recorder.php | 13 +++++++------ src/Codeception/Subscriber/Module.php | 4 ++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/ext/Recorder.php b/ext/Recorder.php index 493398312a..5df29342cf 100644 --- a/ext/Recorder.php +++ b/ext/Recorder.php @@ -301,17 +301,18 @@ class Recorder extends \Codeception\Extension public function beforeSuite(SuiteEvent $e) { $this->webDriverModule = null; - if (!$this->hasModule($this->config['module'])) { - $this->isDisabled = true; - $this->writeln('Recorder is disabled, no available modules'); - return; - } if (!$e->getSuite()->count()) { $this->isDisabled = true; return; // skip for empty suites } + if (!$this->hasModule($this->config['module'])) { + $this->isDisabled = true; + $this->writeln('Recorder is disabled, no available modules'); + return; + } + $this->seed = uniqid(); $this->seeds[] = $this->seed; $this->webDriverModule = $this->getModule($this->config['module']); @@ -342,7 +343,7 @@ public function afterSuite() if ($this->isDisabled) { return; } - + $links = ''; if (count($this->slides)) { diff --git a/src/Codeception/Subscriber/Module.php b/src/Codeception/Subscriber/Module.php index b6fc8e76da..6c4b5fbabd 100644 --- a/src/Codeception/Subscriber/Module.php +++ b/src/Codeception/Subscriber/Module.php @@ -33,6 +33,10 @@ public function beforeSuite(SuiteEvent $e) if (!$suite instanceof Suite) { return; } + if (!$e->getSuite()->getTestCount()) { + $this->modules = []; + return true; // do not launch on empty suite + } $this->modules = $suite->getModules(); foreach ($this->modules as $module) { $module->_beforeSuite($e->getSettings()); From c40860dac3f43fe2ae99f265e80b3cee9ad53f52 Mon Sep 17 00:00:00 2001 From: Davert Date: Sat, 3 Sep 2022 13:21:29 +0300 Subject: [PATCH 3/4] fixed counting tests in suite --- src/Codeception/Subscriber/Module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Codeception/Subscriber/Module.php b/src/Codeception/Subscriber/Module.php index 6c4b5fbabd..f12004b3b0 100644 --- a/src/Codeception/Subscriber/Module.php +++ b/src/Codeception/Subscriber/Module.php @@ -33,7 +33,7 @@ public function beforeSuite(SuiteEvent $e) if (!$suite instanceof Suite) { return; } - if (!$e->getSuite()->getTestCount()) { + if (!count($e->getSuite()->count())) { $this->modules = []; return true; // do not launch on empty suite } From 93bb57fea2a13d15ff40b402db8a1fd619cdf49a Mon Sep 17 00:00:00 2001 From: Davert Date: Sat, 3 Sep 2022 17:30:12 +0300 Subject: [PATCH 4/4] fixed counting tests in suite --- src/Codeception/Subscriber/Module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Codeception/Subscriber/Module.php b/src/Codeception/Subscriber/Module.php index f12004b3b0..8cf9ae9a81 100644 --- a/src/Codeception/Subscriber/Module.php +++ b/src/Codeception/Subscriber/Module.php @@ -33,7 +33,7 @@ public function beforeSuite(SuiteEvent $e) if (!$suite instanceof Suite) { return; } - if (!count($e->getSuite()->count())) { + if (!$e->getSuite()->count()) { $this->modules = []; return true; // do not launch on empty suite }