/** * Retrieve flag object * * @return \Magento\Reports\Model\Flag */ protected function _getFlag() { if ($this->_flag === null) { $this->_flag = $this->_reportsFlagFactory->create(); } return $this->_flag; }
/** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @return void */ protected function setUp() { $this->zendDbMock = $this->getMockBuilder('Zend_Db_Statement_Interface')->getMock(); $this->zendDbMock->expects($this->any())->method('fetchColumn')->willReturn([]); $this->selectMock = $this->getMockBuilder('Magento\\Framework\\DB\\Select')->disableOriginalConstructor()->setMethods(['from', 'where', 'joinInner', 'joinLeft', 'having', 'useStraightJoin', 'insertFromSelect', '__toString'])->getMock(); $this->selectMock->expects($this->any())->method('from')->willReturnSelf(); $this->selectMock->expects($this->any())->method('where')->willReturnSelf(); $this->selectMock->expects($this->any())->method('joinInner')->willReturnSelf(); $this->selectMock->expects($this->any())->method('joinLeft')->willReturnSelf(); $this->selectMock->expects($this->any())->method('having')->willReturnSelf(); $this->selectMock->expects($this->any())->method('useStraightJoin')->willReturnSelf(); $this->selectMock->expects($this->any())->method('insertFromSelect')->willReturnSelf(); $this->selectMock->expects($this->any())->method('__toString')->willReturn('string'); $this->connectionMock = $this->getMockBuilder('Magento\\Framework\\DB\\Adapter\\AdapterInterface')->getMock(); $this->connectionMock->expects($this->any())->method('select')->willReturn($this->selectMock); $this->connectionMock->expects($this->any())->method('query')->willReturn($this->zendDbMock); $this->resourceMock = $this->getMockBuilder('Magento\\Framework\\App\\Resource')->disableOriginalConstructor()->getMock(); $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->connectionMock); $this->resourceMock->expects($this->any())->method('getTableName')->will($this->returnCallback(function ($arg) { return $arg; })); $this->contextMock = $this->getMockBuilder('Magento\\Framework\\Model\\Resource\\Db\\Context')->disableOriginalConstructor()->getMock(); $this->contextMock->expects($this->any())->method('getResources')->willReturn($this->resourceMock); $this->loggerMock = $this->getMockBuilder('Psr\\Log\\LoggerInterface')->getMock(); $dateTime = $this->getMockBuilder('DateTime')->getMock(); $this->timezoneMock = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface')->getMock(); $this->timezoneMock->expects($this->any())->method('scopeDate')->willReturn($dateTime); $this->dateTimeMock = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime')->getMock(); $this->flagMock = $this->getMockBuilder('Magento\\Reports\\Model\\Flag')->disableOriginalConstructor()->setMethods(['setReportFlagCode', 'unsetData', 'loadSelf', 'setFlagData', 'setLastUpdate', 'save'])->getMock(); $this->flagFactoryMock = $this->getMockBuilder('Magento\\Reports\\Model\\FlagFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->flagFactoryMock->expects($this->any())->method('create')->willReturn($this->flagMock); $this->validatorMock = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime\\Timezone\\Validator')->disableOriginalConstructor()->getMock(); $this->backendMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\AbstractBackend')->disableOriginalConstructor()->getMock(); $this->attributeMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute')->disableOriginalConstructor()->getMock(); $this->attributeMock->expects($this->any())->method('getBackend')->willReturn($this->backendMock); $this->productMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Resource\\Product')->disableOriginalConstructor()->getMock(); $this->productMock->expects($this->any())->method('getAttribute')->willReturn($this->attributeMock); $this->helperMock = $this->getMockBuilder('Magento\\Reports\\Model\\Resource\\Helper')->disableOriginalConstructor()->getMock(); $this->viewed = new Viewed($this->contextMock, $this->loggerMock, $this->timezoneMock, $this->flagFactoryMock, $this->dateTimeMock, $this->validatorMock, $this->productMock, $this->helperMock); }
/** * Get if updated * * @param string $reportCode * @return string|\DateTime */ protected function _getUpdatedAt($reportCode) { $flag = $this->_reportsFlagFactory->create()->setReportFlagCode($reportCode)->loadSelf(); return $flag->hasData() ? $this->_localeDate->scopeDate(0, $flag->getLastUpdate(), true) : ''; }
/** * Get if updated * * @param string $reportCode * @return string|\Magento\Framework\Stdlib\DateTime\DateInterface */ protected function _getUpdatedAt($reportCode) { $flag = $this->_reportsFlagFactory->create()->setReportFlagCode($reportCode)->loadSelf(); return $flag->hasData() ? $this->_localeDate->scopeDate(0, new \Magento\Framework\Stdlib\DateTime\Date($flag->getLastUpdate(), \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT), true) : ''; }