diff --git a/ext/Recorder.php b/ext/Recorder.php index 54eda50af0..5df29342cf 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,12 +296,20 @@ class Recorder extends \Codeception\Extension /** @var string */ private $dateFormat; - public function beforeSuite() + private $isDisabled = false; + + public function beforeSuite(SuiteEvent $e) { $this->webDriverModule = null; + + 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; } @@ -331,9 +340,10 @@ public function beforeSuite() public function afterSuite() { - if (!$this->webDriverModule) { + if ($this->isDisabled) { return; } + $links = ''; if (count($this->slides)) { @@ -380,7 +390,7 @@ public function afterSuite() */ public function before(TestEvent $e) { - if (!$this->webDriverModule) { + if ($this->isDisabled) { return; } $this->dir = null; @@ -407,6 +417,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 +459,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 +563,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) { diff --git a/src/Codeception/Subscriber/Module.php b/src/Codeception/Subscriber/Module.php index b6fc8e76da..8cf9ae9a81 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()->count()) { + $this->modules = []; + return true; // do not launch on empty suite + } $this->modules = $suite->getModules(); foreach ($this->modules as $module) { $module->_beforeSuite($e->getSettings());