diff --git a/composer.json b/composer.json index 01a13a5a..c742c7e7 100644 --- a/composer.json +++ b/composer.json @@ -74,7 +74,7 @@ "allow-plugins": { "infection/extension-installer": true, "composer/package-versions-deprecated": true, - "yiisoft/config": true + "yiisoft/config": false } }, "scripts": { diff --git a/src/Debug/QueueCollector.php b/src/Debug/QueueCollector.php index 759efda3..da9f45f4 100644 --- a/src/Debug/QueueCollector.php +++ b/src/Debug/QueueCollector.php @@ -21,6 +21,10 @@ final class QueueCollector implements SummaryCollectorInterface public function getCollected(): array { + if (!$this->isActive()) { + return []; + } + return [ 'pushes' => $this->pushes, 'statuses' => $this->statuses, @@ -77,6 +81,10 @@ private function reset(): void public function getSummary(): array { + if (!$this->isActive()) { + return []; + } + $countPushes = array_sum(array_map(fn ($messages) => is_countable($messages) ? count($messages) : 0, $this->pushes)); $countStatuses = count($this->statuses); $countProcessingMessages = array_sum(array_map(fn ($messages) => is_countable($messages) ? count($messages) : 0, $this->processingMessages)); diff --git a/tests/Unit/Debug/QueueCollectorTest.php b/tests/Unit/Debug/QueueCollectorTest.php index 6aa78e9d..73911ff7 100644 --- a/tests/Unit/Debug/QueueCollectorTest.php +++ b/tests/Unit/Debug/QueueCollectorTest.php @@ -5,7 +5,6 @@ namespace Yiisoft\Yii\Queue\Tests\Unit\Debug; use Yiisoft\Yii\Debug\Collector\CollectorInterface; -use Yiisoft\Yii\Debug\Collector\SummaryCollectorInterface; use Yiisoft\Yii\Debug\Tests\Shared\AbstractCollectorTestCase; use Yiisoft\Yii\Queue\Debug\QueueCollector; use Yiisoft\Yii\Queue\Enum\JobStatus; @@ -105,19 +104,4 @@ protected function checkSummaryData(array $data): void $this->assertEquals(1, $countStatuses); $this->assertEquals(3, $countProcessingMessages); } - - public function testEmptyCollector(): void - { - $collector = $this->getCollector(); - - foreach ($collector->getCollected() as $collected) { - $this->assertEquals([], $collected); - } - - if ($collector instanceof SummaryCollectorInterface) { - foreach ($collector->getSummary()['queue'] as $count) { - $this->assertEquals(0, $count); - } - } - } }