From 9992c0e30b4e368ca978be334c541996c66207cc Mon Sep 17 00:00:00 2001 From: Eden Date: Sat, 23 Nov 2019 22:41:29 +0700 Subject: [PATCH] refactor code to pass review --- .../Test/Unit/CustomerData/CaptchaTest.php | 37 +++++++------------ 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/app/code/Magento/Captcha/Test/Unit/CustomerData/CaptchaTest.php b/app/code/Magento/Captcha/Test/Unit/CustomerData/CaptchaTest.php index b34de7778e176..a791039fe27f9 100644 --- a/app/code/Magento/Captcha/Test/Unit/CustomerData/CaptchaTest.php +++ b/app/code/Magento/Captcha/Test/Unit/CustomerData/CaptchaTest.php @@ -14,28 +14,19 @@ use Magento\Captcha\Model\DefaultModel; use Magento\Customer\Api\Data\CustomerInterface as CustomerData; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; +use PHPUnit\Framework\TestCase; -/** - * Test class to cover \Magento\Captcha\CustomerData\Captcha - * - * Class \Magento\Captcha\Test\Unit\CustomerData\CaptchaTest - */ -class CaptchaTest extends \PHPUnit\Framework\TestCase +class CaptchaTest extends TestCase { /** * @var CaptchaHelper|\PHPUnit_Framework_MockObject_MockObject */ - private $helper; + private $helperMock; /** * @var CustomerSession|\PHPUnit_Framework_MockObject_MockObject */ - private $customerSession; - - /** - * @var CustomerData|\PHPUnit_Framework_MockObject_MockObject - */ - private $customerData; + private $customerSessionMock; /** * @var Captcha @@ -57,8 +48,8 @@ class CaptchaTest extends \PHPUnit\Framework\TestCase */ protected function setUp() { - $this->helper = $this->createMock(CaptchaHelper::class); - $this->customerSession = $this->createMock(CustomerSession::class); + $this->helperMock = $this->createMock(CaptchaHelper::class); + $this->customerSessionMock = $this->createMock(CustomerSession::class); $this->formIds = [ 'user_login' ]; @@ -66,9 +57,9 @@ protected function setUp() $this->model = $this->objectManagerHelper->getObject( Captcha::class, [ - 'helper' => $this->helper, + 'helper' => $this->helperMock, 'formIds' => $this->formIds, - 'customerSession' => $this->customerSession + 'customerSession' => $this->customerSessionMock ] ); } @@ -83,15 +74,15 @@ public function testGetSectionDataWhenLoginAndRequireCaptcha() $userLoginModel = $this->createMock(DefaultModel::class); $userLoginModel->expects($this->any())->method('isRequired')->with($emailLogin) ->willReturn(true); - $this->helper->expects($this->any())->method('getCaptcha')->with('user_login')->willReturn($userLoginModel); + $this->helperMock->expects($this->any())->method('getCaptcha')->with('user_login')->willReturn($userLoginModel); - $this->customerSession->expects($this->any())->method('isLoggedIn') + $this->customerSessionMock->expects($this->any())->method('isLoggedIn') ->willReturn(true); - $this->customerData = $this->createMock(CustomerData::class); - $this->customerData->expects($this->any())->method('getEmail')->willReturn($emailLogin); - $this->customerSession->expects($this->any())->method('getCustomerData') - ->willReturn($this->customerData); + $customerDataMock = $this->createMock(CustomerData::class); + $customerDataMock->expects($this->any())->method('getEmail')->willReturn($emailLogin); + $this->customerSessionMock->expects($this->any())->method('getCustomerData') + ->willReturn($customerDataMock); /* Assert to test */ $this->assertEquals(