Skip to content

Commit

Permalink
refactor code to pass review
Browse files Browse the repository at this point in the history
  • Loading branch information
edenduong committed Nov 23, 2019
1 parent 7534f33 commit 9992c0e
Showing 1 changed file with 14 additions and 23 deletions.
37 changes: 14 additions & 23 deletions app/code/Magento/Captcha/Test/Unit/CustomerData/CaptchaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -57,18 +48,18 @@ 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'
];
$this->objectManagerHelper = new ObjectManagerHelper($this);
$this->model = $this->objectManagerHelper->getObject(
Captcha::class,
[
'helper' => $this->helper,
'helper' => $this->helperMock,
'formIds' => $this->formIds,
'customerSession' => $this->customerSession
'customerSession' => $this->customerSessionMock
]
);
}
Expand All @@ -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(
Expand Down

0 comments on commit 9992c0e

Please sign in to comment.