72 $this->contextMock = $this->getMockBuilder(\
Magento\Backend\
App\Action\Context::class)
73 ->disableOriginalConstructor()
75 $this->authenticationMock = $this->getMockBuilder(AuthenticationInterface::class)
76 ->disableOriginalConstructor()
79 $this->requestMock = $this->getMockBuilder(\
Magento\Framework\
App\RequestInterface::class)
80 ->setMethods([
'getParam'])
81 ->getMockForAbstractClass();
82 $this->messageManagerMock = $this->createMock(\
Magento\Framework\Message\ManagerInterface::class);
83 $this->resultFactoryMock = $this->createPartialMock(
84 \
Magento\Framework\Controller\ResultFactory::class,
87 $this->redirectMock = $this->createPartialMock(\
Magento\Backend\Model\View\Result\Redirect::class, [
'setPath']);
88 $this->customerDataMock = $this->createMock(\
Magento\Customer\Model\Data\Customer::class);
89 $this->contextMock = $this->getMockBuilder(\
Magento\Backend\
App\Action\Context::class)
90 ->setMethods([
'getObjectManager',
'getResultFactory',
'getMessageManager',
'getRequest'])
91 ->disableOriginalConstructor()
94 $this->contextMock->expects($this->any())
95 ->method(
'getRequest')
96 ->willReturn($this->requestMock);
97 $this->contextMock->expects($this->any())->method(
'getMessageManager')->willReturn($this->messageManagerMock);
98 $this->contextMock->expects($this->any())->method(
'getResultFactory')->willReturn($this->resultFactoryMock);
99 $this->resultFactoryMock->expects($this->once())->method(
'create')->willReturn($this->redirectMock);
101 $this->controller = $this->objectManager->getObject(
102 \
Magento\Customer\Controller\Adminhtml\Locks\Unlock::class,
104 'context' => $this->contextMock,
105 'authentication' => $this->authenticationMock,
116 $this->requestMock->expects($this->once())
118 ->with($this->equalTo(
'customer_id'))
120 $this->authenticationMock->expects($this->once())->method(
'unlock')->with(
$customerId);
121 $this->messageManagerMock->expects($this->once())->method(
'addSuccess');
122 $this->redirectMock->expects($this->once())
124 ->with($this->equalTo(
'customer/index/edit'))
126 $this->assertInstanceOf(\
Magento\Backend\Model\View\Result\Redirect::class, $this->controller->execute());
135 $phrase = new \Magento\Framework\Phrase(
'some error');
136 $this->requestMock->expects($this->once())
138 ->with($this->equalTo(
'customer_id'))
140 $this->authenticationMock->expects($this->once())
143 ->willThrowException(
new \Exception($phrase));
144 $this->messageManagerMock->expects($this->once())->method(
'addError');
145 $this->controller->execute();
testExecuteWithException()