/** * @expectedException \Magento\Framework\Exception\CouldNotSaveException * @expectedExceptionMessage Cannot create quote */ public function testCreateWithException() { $storeId = 345; $this->storeManagerMock->expects($this->once())->method('getStore')->will($this->returnValue($this->storeMock)); $this->storeMock->expects($this->once())->method('getId')->will($this->returnValue($storeId)); $this->quoteFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->quoteMock)); $this->quoteMock->expects($this->once())->method('setStoreId')->with($storeId); $this->quoteMock->expects($this->once())->method('save')->will($this->throwException(new CouldNotSaveException('Cannot create quote'))); $this->service->create(); }