/** * Reports category size to the database reporting_counts table * * @return void */ protected function reportCategorySize() { $categoryCount = $this->categoryManagement->getCount(); /** @var \Magento\NewRelicReporting\Model\Counts $model */ $model = $this->countsFactory->create()->load(Config::CATEGORY_SIZE, 'type'); $this->updateCount($categoryCount, $model, Config::CATEGORY_SIZE); }
/** * Setup * * @return void */ public function setUp() { $this->configMock = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\Config')->disableOriginalConstructor()->setMethods(['isNewRelicEnabled'])->getMock(); $this->productManagementMock = $this->getMockBuilder('Magento\\Catalog\\Api\\ProductManagementInterface')->disableOriginalConstructor()->getMock(); $this->configurableManagementMock = $this->getMockBuilder('Magento\\ConfigurableProduct\\Api\\ConfigurableProductManagementInterface')->disableOriginalConstructor()->getMock(); $this->categoryManagementMock = $this->getMockBuilder('Magento\\Catalog\\Api\\CategoryManagementInterface')->disableOriginalConstructor()->getMock(); $this->countsFactoryMock = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\CountsFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->countsModelMock = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\Counts')->disableOriginalConstructor()->getMock(); $this->countsCollectionFactoryMock = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\ResourceModel\\Counts\\CollectionFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $collectionClassName = 'Magento\\NewRelicReporting\\Model\\ResourceModel\\Counts\\Collection'; $this->countsCollectionMock = $this->getMockBuilder($collectionClassName)->disableOriginalConstructor()->setMethods(['addFieldToFilter', 'addOrder', 'setPageSize', 'getFirstItem'])->getMock(); $this->countsFactoryMock->expects($this->any())->method('create')->willReturn($this->countsModelMock); $this->countsModelMock->expects($this->any())->method('load')->willReturnSelf(); $this->countsCollectionFactoryMock->expects($this->any())->method('create')->willReturn($this->countsCollectionMock); $this->countsCollectionMock->expects($this->any())->method('addFieldToFilter')->willReturnSelf(); $this->countsCollectionMock->expects($this->any())->method('addOrder')->willReturnSelf(); $this->countsCollectionMock->expects($this->any())->method('setPageSize')->willReturnSelf(); $this->countsCollectionMock->expects($this->any())->method('getFirstItem')->willReturn($this->countsModelMock); $this->model = new ReportCounts($this->configMock, $this->productManagementMock, $this->configurableManagementMock, $this->categoryManagementMock, $this->countsFactoryMock, $this->countsCollectionFactoryMock); }