public function testExecuteException() { $queryId = 1; $queryText = 'search'; $this->mockGetRequestData($queryText, $queryId); $this->request->expects($this->at(4))->method('getPost')->with('store_id', false)->willReturn(1); $this->query->expects($this->once())->method('setStoreId'); $this->query->expects($this->once())->method('loadByQueryText')->willThrowException(new \Exception()); $this->messageManager->expects($this->once())->method('addException'); $this->session->expects($this->once())->method('setPageData'); $this->redirect->expects($this->once())->method('setPath')->willReturnSelf(); $this->assertSame($this->redirect, $this->controller->execute()); }
/** * @depends testGetNewQuery * @param $query */ public function testGetQueryTwice($query) { $queryId = null; $this->mapScopeConfig([self::XML_PATH_MAX_QUERY_LENGTH => 120]); $rawQueryText = 'Simple product'; $preparedQueryText = $rawQueryText; $this->requestMock->expects($this->once())->method('getParam')->with($this->equalTo(self::QUERY_VAR_NAME))->will($this->returnValue($rawQueryText)); $this->objectManagerMock->expects($this->once())->method('create')->with($this->equalTo('Magento\\Search\\Model\\Query'))->will($this->returnValue($this->queryMock)); $this->queryMock->expects($this->once())->method('loadByQuery')->with($this->equalTo($preparedQueryText))->will($this->returnSelf()); $this->queryMock->expects($this->once())->method('getId')->will($this->returnValue($queryId)); $this->queryMock->expects($this->once())->method('setQueryText')->with($preparedQueryText)->will($this->returnSelf()); $this->queryMock->expects($this->once())->method('setIsQueryTextExceeded')->with($this->equalTo(false))->will($this->returnSelf()); $query = $this->queryFactory->get(); $this->assertSame($this->queryMock, $query); $this->assertSame($query, $this->queryFactory->get()); }
/** * @param string $cleanedRawText * @param void */ private function mockSetQueryTextOnceExecute($cleanedRawText) { $this->query->expects($this->once())->method('setQueryText')->withConsecutive([$cleanedRawText])->willReturnSelf(); }