16
16
use Magento \Persistent \Model \Session as PersistentSession ;
17
17
use Magento \Customer \Api \Data \CustomerInterface ;
18
18
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
19
+ use PHPUnit \Framework \MockObject \MockObject ;
19
20
20
21
class PersistentTest extends TestCase
21
22
{
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
+
22
33
/**
23
34
* @var Persistent
24
35
*/
25
36
private $ customerData ;
26
37
27
38
/**
28
- * @var Session
39
+ * @var Session|MockObject
29
40
*/
30
41
private $ persistentSessionHelperMock ;
31
42
32
43
/**
33
- * @var View
44
+ * @var View|MockObject
34
45
*/
35
46
private $ customerViewHelperMock ;
36
47
37
48
/**
38
- * @var CustomerRepositoryInterface
49
+ * @var CustomerRepositoryInterface|MockObject
39
50
*/
40
51
private $ customerRepositoryMock ;
41
52
@@ -73,7 +84,7 @@ public function testGetSectionDataWhenDisablePersistent()
73
84
/**
74
85
* Test getSectionData() when customer doesn't login
75
86
*/
76
- public function testGetSectionDataWithNotLogin ()
87
+ public function testGetSectionDataWhenCustomerNotLoggedInReturnsEmptyArray ()
77
88
{
78
89
$ this ->persistentSessionHelperMock ->method ('isPersistent ' )->willReturn (true );
79
90
@@ -92,16 +103,17 @@ public function testGetSectionDataCustomerLoginAndEnablePersistent()
92
103
$ this ->persistentSessionHelperMock ->method ('isPersistent ' )->willReturn (true );
93
104
94
105
$ persistentSessionMock = $ this ->createPartialMock (PersistentSession::class, ['getCustomerId ' ]);
95
- $ persistentSessionMock ->method ('getCustomerId ' )->willReturn (1 );
106
+ $ persistentSessionMock ->method ('getCustomerId ' )->willReturn (self :: STUB_CUSTOMER_ID );
96
107
$ this ->persistentSessionHelperMock ->method ('getSession ' )->willReturn ($ persistentSessionMock );
97
108
98
109
$ customerMock = $ this ->createMock (CustomerInterface::class);
99
110
$ 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 );
101
113
102
114
$ this ->assertEquals (
103
115
[
104
- 'fullname ' => ' Adam John '
116
+ 'fullname ' => self :: STUB_CUSTOMER_NAME
105
117
],
106
118
$ this ->customerData ->getSectionData ()
107
119
);
0 commit comments