diff --git a/Test/Unit/Aggregator/Store/WebsiteCountAggregatorTest.php b/Test/Unit/Aggregator/Store/WebsiteCountAggregatorTest.php new file mode 100644 index 0000000..1f6bdf1 --- /dev/null +++ b/Test/Unit/Aggregator/Store/WebsiteCountAggregatorTest.php @@ -0,0 +1,50 @@ +updateMetricService = $this->createMock(UpdateMetricService::class); + $this->websiteRepository = $this->createMock(WebsiteRepositoryInterface::class); + + $this->sut = new WebsiteCountAggregator( + $this->updateMetricService, + $this->websiteRepository + ); + } + + public function testAggregate(): void + { + $this->websiteRepository + ->expects($this->once()) + ->method('getList') + ->willReturn(['a', 'b', 'c', 'd', '3']); + + $this->updateMetricService + ->expects($this->once()) + ->method('update') + ->with(self::METRIC_CODE, '5'); + + $this->sut->aggregate(); + } +} diff --git a/src/Aggregator/Store/WebsiteCountAggregator.php b/src/Aggregator/Store/WebsiteCountAggregator.php new file mode 100644 index 0000000..2935b1c --- /dev/null +++ b/src/Aggregator/Store/WebsiteCountAggregator.php @@ -0,0 +1,54 @@ +updateMetricService = $updateMetricService; + $this->websiteRepository = $websiteRepository; + } + + public function getCode(): string + { + return self::METRIC_CODE; + } + + public function getHelp(): string + { + return 'Magento 2 Website Count.'; + } + + public function getType(): string + { + return 'gauge'; + } + + public function aggregate(): bool + { + $websiteList = $this->websiteRepository->getList(); + $websiteCount = (string)count($websiteList); + + return $this->updateMetricService->update(self::METRIC_CODE, $websiteCount); + } +} diff --git a/src/etc/di.xml b/src/etc/di.xml index 79af7f5..3664098 100644 --- a/src/etc/di.xml +++ b/src/etc/di.xml @@ -53,6 +53,7 @@ RunAsRoot\PrometheusExporter\Aggregator\Store\StoreCountAggregator + RunAsRoot\PrometheusExporter\Aggregator\Store\WebsiteCountAggregator RunAsRoot\PrometheusExporter\Aggregator\User\AdminUserCountAggregator