@@ -1721,4 +1721,102 @@ private function prepareDateTimeFactory()
1721
1721
1722
1722
return $ dateTime ;
1723
1723
}
1724
+
1725
+ public function testCreateAccountUnexpectedValueException ()
1726
+ {
1727
+ $ websiteId = 1 ;
1728
+ $ storeId = null ;
1729
+ $ defaultStoreId = 1 ;
1730
+ $ customerId = 1 ;
1731
+ $ customerEmail =
'[email protected] ' ;
1732
+ $ newLinkToken = '2jh43j5h2345jh23lh452h345hfuzasd96ofu ' ;
1733
+ $ exception = new \UnexpectedValueException ('Template file was not found ' );
1734
+
1735
+ $ datetime = $ this ->prepareDateTimeFactory ();
1736
+
1737
+ $ address = $ this ->createMock (\Magento \Customer \Api \Data \AddressInterface::class);
1738
+ $ address ->expects ($ this ->once ())
1739
+ ->method ('setCustomerId ' )
1740
+ ->with ($ customerId );
1741
+ $ store = $ this ->createMock (\Magento \Store \Model \Store::class);
1742
+ $ store ->expects ($ this ->once ())
1743
+ ->method ('getId ' )
1744
+ ->willReturn ($ defaultStoreId );
1745
+ $ website = $ this ->createMock (\Magento \Store \Model \Website::class);
1746
+ $ website ->expects ($ this ->atLeastOnce ())
1747
+ ->method ('getStoreIds ' )
1748
+ ->willReturn ([1 , 2 , 3 ]);
1749
+ $ website ->expects ($ this ->once ())
1750
+ ->method ('getDefaultStore ' )
1751
+ ->willReturn ($ store );
1752
+ $ customer = $ this ->createMock (\Magento \Customer \Api \Data \CustomerInterface::class);
1753
+ $ customer ->expects ($ this ->atLeastOnce ())
1754
+ ->method ('getId ' )
1755
+ ->willReturn ($ customerId );
1756
+ $ customer ->expects ($ this ->atLeastOnce ())
1757
+ ->method ('getEmail ' )
1758
+ ->willReturn ($ customerEmail );
1759
+ $ customer ->expects ($ this ->atLeastOnce ())
1760
+ ->method ('getWebsiteId ' )
1761
+ ->willReturn ($ websiteId );
1762
+ $ customer ->expects ($ this ->atLeastOnce ())
1763
+ ->method ('getStoreId ' )
1764
+ ->willReturn ($ storeId );
1765
+ $ customer ->expects ($ this ->once ())
1766
+ ->method ('setStoreId ' )
1767
+ ->with ($ defaultStoreId );
1768
+ $ customer ->expects ($ this ->once ())
1769
+ ->method ('getAddresses ' )
1770
+ ->willReturn ([$ address ]);
1771
+ $ customer ->expects ($ this ->once ())
1772
+ ->method ('setAddresses ' )
1773
+ ->with (null );
1774
+ $ this ->customerRepository ->expects ($ this ->once ())
1775
+ ->method ('get ' )
1776
+ ->with ($ customerEmail )
1777
+ ->willReturn ($ customer );
1778
+ $ this ->share ->expects ($ this ->once ())
1779
+ ->method ('isWebsiteScope ' )
1780
+ ->willReturn (true );
1781
+ $ this ->storeManager ->expects ($ this ->atLeastOnce ())
1782
+ ->method ('getWebsite ' )
1783
+ ->with ($ websiteId )
1784
+ ->willReturn ($ website );
1785
+ $ this ->customerRepository ->expects ($ this ->atLeastOnce ())
1786
+ ->method ('save ' )
1787
+ ->willReturn ($ customer );
1788
+ $ this ->addressRepository ->expects ($ this ->atLeastOnce ())
1789
+ ->method ('save ' )
1790
+ ->with ($ address );
1791
+ $ this ->customerRepository ->expects ($ this ->once ())
1792
+ ->method ('getById ' )
1793
+ ->with ($ customerId )
1794
+ ->willReturn ($ customer );
1795
+ $ this ->random ->expects ($ this ->once ())
1796
+ ->method ('getUniqueHash ' )
1797
+ ->willReturn ($ newLinkToken );
1798
+ $ customerSecure = $ this ->createPartialMock (
1799
+ \Magento \Customer \Model \Data \CustomerSecure::class,
1800
+ ['setRpToken ' , 'setRpTokenCreatedAt ' , 'getPasswordHash ' ]
1801
+ );
1802
+ $ customerSecure ->expects ($ this ->any ())
1803
+ ->method ('setRpToken ' )
1804
+ ->with ($ newLinkToken );
1805
+ $ customerSecure ->expects ($ this ->any ())
1806
+ ->method ('setRpTokenCreatedAt ' )
1807
+ ->with ($ datetime )
1808
+ ->willReturnSelf ();
1809
+ $ customerSecure ->expects ($ this ->any ())
1810
+ ->method ('getPasswordHash ' )
1811
+ ->willReturn (null );
1812
+ $ this ->customerRegistry ->expects ($ this ->atLeastOnce ())
1813
+ ->method ('retrieveSecureData ' )
1814
+ ->willReturn ($ customerSecure );
1815
+ $ this ->emailNotificationMock ->expects ($ this ->once ())
1816
+ ->method ('newAccount ' )
1817
+ ->willThrowException ($ exception );
1818
+ $ this ->logger ->expects ($ this ->once ())->method ('error ' )->with ($ exception );
1819
+
1820
+ $ this ->accountManagement ->createAccount ($ customer );
1821
+ }
1724
1822
}
0 commit comments