Skip to content

Commit 5cedaf8

Browse files
committed
Refactor code
1 parent ad48079 commit 5cedaf8

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

app/code/Magento/Persistent/Test/Unit/CustomerData/PersistentTest.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,37 @@
1616
use Magento\Persistent\Model\Session as PersistentSession;
1717
use Magento\Customer\Api\Data\CustomerInterface;
1818
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
19+
use PHPUnit\Framework\MockObject\MockObject;
1920

2021
class PersistentTest extends TestCase
2122
{
23+
/**
24+
* Stub customer id
25+
*/
26+
private const STUB_CUSTOMER_ID = 1;
27+
28+
/**
29+
* Stub customer name
30+
*/
31+
private const STUB_CUSTOMER_NAME = 'Adam John';
32+
2233
/**
2334
* @var Persistent
2435
*/
2536
private $customerData;
2637

2738
/**
28-
* @var Session
39+
* @var Session|MockObject
2940
*/
3041
private $persistentSessionHelperMock;
3142

3243
/**
33-
* @var View
44+
* @var View|MockObject
3445
*/
3546
private $customerViewHelperMock;
3647

3748
/**
38-
* @var CustomerRepositoryInterface
49+
* @var CustomerRepositoryInterface|MockObject
3950
*/
4051
private $customerRepositoryMock;
4152

@@ -73,7 +84,7 @@ public function testGetSectionDataWhenDisablePersistent()
7384
/**
7485
* Test getSectionData() when customer doesn't login
7586
*/
76-
public function testGetSectionDataWithNotLogin()
87+
public function testGetSectionDataWhenCustomerNotLoggedInReturnsEmptyArray()
7788
{
7889
$this->persistentSessionHelperMock->method('isPersistent')->willReturn(true);
7990

@@ -92,16 +103,17 @@ public function testGetSectionDataCustomerLoginAndEnablePersistent()
92103
$this->persistentSessionHelperMock->method('isPersistent')->willReturn(true);
93104

94105
$persistentSessionMock = $this->createPartialMock(PersistentSession::class, ['getCustomerId']);
95-
$persistentSessionMock->method('getCustomerId')->willReturn(1);
106+
$persistentSessionMock->method('getCustomerId')->willReturn(self::STUB_CUSTOMER_ID);
96107
$this->persistentSessionHelperMock->method('getSession')->willReturn($persistentSessionMock);
97108

98109
$customerMock = $this->createMock(CustomerInterface::class);
99110
$this->customerRepositoryMock->method('getById')->with(1)->willReturn($customerMock);
100-
$this->customerViewHelperMock->method('getCustomerName')->with($customerMock)->willReturn('Adam John');
111+
$this->customerViewHelperMock->method('getCustomerName')->with($customerMock)
112+
->willReturn(self::STUB_CUSTOMER_NAME);
101113

102114
$this->assertEquals(
103115
[
104-
'fullname' => 'Adam John'
116+
'fullname' => self::STUB_CUSTOMER_NAME
105117
],
106118
$this->customerData->getSectionData()
107119
);

0 commit comments

Comments
 (0)