12
12
use Magento \Customer \Model \Context as CustomerContext ;
13
13
use Magento \Customer \Model \Customer ;
14
14
use Magento \Customer \Model \CustomerFactory ;
15
+ use Magento \Customer \Model \CustomerRegistry ;
15
16
use Magento \Customer \Model \ResourceModel \Customer as ResourceCustomer ;
16
17
use Magento \Customer \Model \Session ;
17
18
use Magento \Customer \Model \Session \Storage ;
18
19
use Magento \Framework \App \Http \Context ;
19
20
use Magento \Framework \App \Response \Http ;
20
21
use Magento \Framework \Event \ManagerInterface ;
22
+ use Magento \Framework \Exception \NoSuchEntityException ;
21
23
use Magento \Framework \Session \SessionStartChecker ;
22
24
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
23
25
use Magento \Framework \Url ;
@@ -70,6 +72,11 @@ class SessionTest extends TestCase
70
72
*/
71
73
protected $ responseMock ;
72
74
75
+ /**
76
+ * @var CustomerRegistry|MockObject
77
+ */
78
+ private $ customerRegistryMock ;
79
+
73
80
/**
74
81
* @var Session
75
82
*/
@@ -105,6 +112,7 @@ protected function setUp(): void
105
112
];
106
113
$ helper ->prepareObjectManager ($ objects );
107
114
$ this ->responseMock = $ this ->createMock (Http::class);
115
+ $ this ->customerRegistryMock = $ this ->createMock (CustomerRegistry::class);
108
116
$ this ->_model = $ helper ->getObject (
109
117
Session::class,
110
118
[
@@ -115,7 +123,8 @@ protected function setUp(): void
115
123
'urlFactory ' => $ this ->urlFactoryMock ,
116
124
'customerRepository ' => $ this ->customerRepositoryMock ,
117
125
'response ' => $ this ->responseMock ,
118
- '_customerResource ' => $ this ->_customerResourceMock
126
+ '_customerResource ' => $ this ->_customerResourceMock ,
127
+ 'customerRegistry ' => $ this ->customerRegistryMock ,
119
128
]
120
129
);
121
130
}
@@ -342,4 +351,27 @@ public function testSetCustomer(): void
342
351
343
352
$ this ->_model ->setCustomer ($ customer );
344
353
}
354
+
355
+ public function testCheckCustomerId (): void
356
+ {
357
+ $ customerId = 123 ;
358
+ $ customer = $ this ->createMock (Customer::class);
359
+ $ this ->customerRegistryMock ->expects ($ this ->once ())
360
+ ->method ('retrieve ' )
361
+ ->with ($ customerId )
362
+ ->willReturn ($ customer );
363
+ $ result = $ this ->_model ->checkCustomerId ($ customerId );
364
+ $ this ->assertTrue ($ result );
365
+ }
366
+
367
+ public function testCheckCustomerIdInvalid (): void
368
+ {
369
+ $ customerId = 123 ;
370
+ $ this ->customerRegistryMock ->expects ($ this ->once ())
371
+ ->method ('retrieve ' )
372
+ ->with ($ customerId )
373
+ ->willThrowException (new NoSuchEntityException ());
374
+ $ result = $ this ->_model ->checkCustomerId ($ customerId );
375
+ $ this ->assertFalse ($ result );
376
+ }
345
377
}
0 commit comments