subscriptionHandlerMock = $this->getMockBuilder(SubscriptionHandler::class) ->disableOriginalConstructor() ->getMock(); $this->loggerMock = $this->getMockBuilder(LoggerInterface::class) ->disableOriginalConstructor() ->getMock(); $this->configMock = $this->getMockBuilder(ScopeConfigInterface::class) ->disableOriginalConstructor() ->getMock(); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->enabledModel = $this->objectManagerHelper->getObject( Enabled::class, [ 'subscriptionHandler' => $this->subscriptionHandlerMock, '_logger' => $this->loggerMock, 'config' => $this->configMock, ] ); } /** * @return void */ public function testAfterSaveSuccessEnabled() { $this->enabledModel->setData('value', $this->valueEnabled); $this->configMock ->expects($this->any()) ->method('getValue') ->willReturn(!$this->valueEnabled); $this->subscriptionHandlerMock ->expects($this->once()) ->method('processEnabled') ->with() ->willReturn(true); $this->assertInstanceOf( Value::class, $this->enabledModel->afterSave() ); } /** * @return void */ public function testAfterSaveSuccessDisabled() { $this->enabledModel->setData('value', $this->valueDisabled); $this->configMock ->expects($this->any()) ->method('getValue') ->willReturn(!$this->valueDisabled); $this->subscriptionHandlerMock ->expects($this->once()) ->method('processDisabled') ->with() ->willReturn(true); $this->assertInstanceOf( Value::class, $this->enabledModel->afterSave() ); } /** * @return void */ public function testAfterSaveSuccessValueNotChanged() { $this->enabledModel->setData('value', null); $this->configMock ->expects($this->any()) ->method('getValue') ->willReturn(null); $this->subscriptionHandlerMock ->expects($this->never()) ->method('processEnabled') ->with() ->willReturn(true); $this->subscriptionHandlerMock ->expects($this->never()) ->method('processDisabled') ->with() ->willReturn(true); $this->assertInstanceOf( Value::class, $this->enabledModel->afterSave() ); } /** * @return void * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testExecuteAfterSaveFailedWithLocalizedException() { $exception = new \Exception('Message'); $this->enabledModel->setData('value', $this->valueEnabled); $this->subscriptionHandlerMock ->expects($this->once()) ->method('processEnabled') ->with() ->willThrowException($exception); $this->loggerMock ->expects($this->once()) ->method('error') ->with($exception->getMessage()); $this->enabledModel->afterSave(); } }