public function testExecuteException() { $redirectPath = 'path/to/redirect'; $quoteMock = $this->getQuoteMock(); $quoteMock->expects(self::once())->method('getItemsCount')->willReturn(0); $this->requestMock->expects(self::exactly(1))->method('getParam')->willReturnMap([['isAjax', null, true]]); $this->checkoutSessionMock->expects(self::once())->method('getQuote')->willReturn($quoteMock); $this->shippingMethodUpdaterMock->expects(self::never())->method('execute'); $this->messageManagerMock->expects(self::once())->method('addExceptionMessage')->with(self::isInstanceOf('\\InvalidArgumentException'), 'We can\'t initialize checkout.'); $this->urlMock->expects(self::once())->method('getUrl')->with('*/*/review', ['_secure' => true])->willReturn($redirectPath); $this->responseMock->expects(self::once())->method('setBody')->with(sprintf('<script>window.location.href = "%s";</script>', $redirectPath)); $this->saveShippingMethod->execute(); }