1212use Magento \Customer \Model \Context as CustomerContext ;
1313use Magento \Customer \Model \Customer ;
1414use Magento \Customer \Model \CustomerFactory ;
15+ use Magento \Customer \Model \CustomerRegistry ;
1516use Magento \Customer \Model \ResourceModel \Customer as ResourceCustomer ;
1617use Magento \Customer \Model \Session ;
1718use Magento \Customer \Model \Session \Storage ;
1819use Magento \Framework \App \Http \Context ;
1920use Magento \Framework \App \Response \Http ;
2021use Magento \Framework \Event \ManagerInterface ;
22+ use Magento \Framework \Exception \NoSuchEntityException ;
2123use Magento \Framework \Session \SessionStartChecker ;
2224use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
2325use Magento \Framework \Url ;
@@ -70,6 +72,11 @@ class SessionTest extends TestCase
7072 */
7173 protected $ responseMock ;
7274
75+ /**
76+ * @var CustomerRegistry|MockObject
77+ */
78+ private $ customerRegistryMock ;
79+
7380 /**
7481 * @var Session
7582 */
@@ -105,6 +112,7 @@ protected function setUp(): void
105112 ];
106113 $ helper ->prepareObjectManager ($ objects );
107114 $ this ->responseMock = $ this ->createMock (Http::class);
115+ $ this ->customerRegistryMock = $ this ->createMock (CustomerRegistry::class);
108116 $ this ->_model = $ helper ->getObject (
109117 Session::class,
110118 [
@@ -115,7 +123,8 @@ protected function setUp(): void
115123 'urlFactory ' => $ this ->urlFactoryMock ,
116124 'customerRepository ' => $ this ->customerRepositoryMock ,
117125 'response ' => $ this ->responseMock ,
118- '_customerResource ' => $ this ->_customerResourceMock
126+ '_customerResource ' => $ this ->_customerResourceMock ,
127+ 'customerRegistry ' => $ this ->customerRegistryMock ,
119128 ]
120129 );
121130 }
@@ -342,4 +351,27 @@ public function testSetCustomer(): void
342351
343352 $ this ->_model ->setCustomer ($ customer );
344353 }
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+ }
345377}
0 commit comments