/** * Test for create method */ public function testCreate() { $data = [1, 2, 3]; $this->objectManager->expects($this->once())->method('create')->withConsecutive([Query::class, $data])->willReturn($this->query); $result = $this->model->create($data); $this->assertSame($this->query, $result); }
/** * Create\Load Query model instance * * @return \Magento\Search\Model\Query * @throws \Magento\Framework\Exception\LocalizedException */ private function loadQuery() { //validate query $queryText = $this->getRequest()->getPost('query_text', false); $queryId = $this->getRequest()->getPost('query_id', null); /* @var $model \Magento\Search\Model\Query */ $model = $this->queryFactory->create(); if ($queryText) { $storeId = $this->getRequest()->getPost('store_id', false); $model->setStoreId($storeId); $model->loadByQueryText($queryText); if ($model->getId() && $model->getId() != $queryId) { throw new \Magento\Framework\Exception\LocalizedException(__('You already have an identical search term query.')); } } if ($queryId && !$model->getId()) { $model->load($queryId); } return $model; }
public function testCreate() { $this->objectManagerMock->expects($this->once())->method('create')->with($this->equalTo('Magento\\Search\\Model\\Query'))->will($this->returnValue($this->queryMock)); $query = $this->queryFactory->create(); $this->assertSame($this->queryMock, $query); }