Beispiel #1
0
 public function testSyncCustomerGrid()
 {
     $gridTable = 'customer_grid_flat';
     $customerLogTable = 'customer_log';
     $this->indexerRegistry->expects($this->once())->method('get')->with(\Magento\Customer\Model\Customer::CUSTOMER_GRID_INDEXER_ID)->willReturn($this->indexer);
     $this->resource->expects($this->once())->method('getConnection')->willReturn($this->connection);
     $this->flatScopeResolver->expects($this->once())->method('resolve')->with(\Magento\Customer\Model\Customer::CUSTOMER_GRID_INDEXER_ID, [])->willReturn($gridTable);
     $this->resource->expects($this->exactly(2))->method('getTableName')->willReturnMap([[$gridTable], [$customerLogTable]]);
     $this->connection->expects($this->exactly(2))->method('select')->willReturn($this->select);
     $this->select->expects($this->exactly(2))->method('from')->willReturnSelf();
     $this->select->expects($this->once())->method('order')->with('last_visit_at DESC')->willReturnSelf();
     $this->select->expects($this->once())->method('limit')->with(1)->willReturnSelf();
     $this->connection->expects($this->atLeastOnce())->method('query')->with($this->select)->willReturn($this->queryResult);
     $this->queryResult->expects($this->once())->method('fetchColumn')->willReturn('2015-08-13 10:36:44');
     $this->select->expects($this->once())->method('where')->with('last_login_at > ?', '2015-08-13 10:36:44')->willReturnSelf();
     $this->queryResult->expects($this->once())->method('fetchAll')->willReturn([['customer_id' => 23], ['customer_id' => 65]]);
     $this->indexer->expects($this->once())->method('reindexList')->with(['23', '65']);
     $this->observer->syncCustomerGrid();
 }
 /**
  * @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\\ResourceConnection')->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\\ResourceModel\\Db\\Context')->disableOriginalConstructor()->getMock();
     $this->contextMock->expects($this->any())->method('getResources')->willReturn($this->resourceMock);
     $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->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->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\\ResourceModel\\Product')->disableOriginalConstructor()->getMock();
     $this->productMock->expects($this->any())->method('getAttribute')->willReturn($this->attributeMock);
     $this->helperMock = $this->getMockBuilder('Magento\\Reports\\Model\\ResourceModel\\Helper')->disableOriginalConstructor()->getMock();
     $this->viewed = (new ObjectManager($this))->getObject('Magento\\Reports\\Model\\ResourceModel\\Report\\Product\\Viewed', ['context' => $this->contextMock, 'localeDate' => $this->timezoneMock, 'reportsFlagFactory' => $this->flagFactoryMock, 'productResource' => $this->productMock, 'resourceHelper' => $this->helperMock]);
 }