1
+ <?php
2
+
3
+ namespace Magento \Customer \Test \Unit \Observer ;
4
+
5
+ use Magento \Customer \Observer \UpgradeQuoteCustomerEmailObserver ;
6
+
7
+ /**
8
+ * Class UpgradeQuoteCustomerEmailObserverTest for testing upgrade quote customer email
9
+ */
10
+ class UpgradeQuoteCustomerEmailObserverTest extends \PHPUnit \Framework \TestCase
11
+ {
12
+ /**
13
+ * @var UpgradeQuoteCustomerEmailObserver
14
+ */
15
+ protected $ model ;
16
+
17
+ /**
18
+ * @var \Magento\Quote\Api\CartRepositoryInterface
19
+ */
20
+ protected $ quoteRepositoryMock ;
21
+
22
+ protected $ observerMock ;
23
+
24
+ protected $ eventMock ;
25
+
26
+ /**
27
+ * @inheritdoc
28
+ */
29
+ protected function setUp ()
30
+ {
31
+ $ this ->observerMock = $ this ->getMockBuilder (\Magento \Framework \Event \Observer::class)
32
+ ->disableOriginalConstructor ()
33
+ ->getMock ();
34
+
35
+ $ this ->eventMock = $ this ->getMockBuilder (\Magento \Framework \Event::class)
36
+ ->disableOriginalConstructor ()
37
+ ->setMethods (['getCustomerDataObject ' , 'getOrigCustomerDataObject ' ])
38
+ ->getMock ();
39
+
40
+ $ this ->observerMock ->expects ($ this ->any ())->method ('getEvent ' )->will ($ this ->returnValue ($ this ->eventMock ));
41
+
42
+ $ this ->quoteRepositoryMock = $ this
43
+ ->getMockBuilder (\Magento \Quote \Api \CartRepositoryInterface::class)
44
+ ->getMockForAbstractClass ();
45
+ $ this ->model = new UpgradeQuoteCustomerEmailObserver ($ this ->quoteRepositoryMock );
46
+ }
47
+
48
+ /**
49
+ *
50
+ */
51
+ public function testUpgradeQuoteCustomerEmail ()
52
+ {
53
+
54
+
55
+
56
+ $ customer = $ this ->getMockBuilder (\Magento \Customer \Api \Data \CustomerInterface::class)
57
+ ->disableOriginalConstructor ()
58
+ ->getMock ();
59
+ $ customerOrig = $ this ->getMockBuilder (\Magento \Customer \Api \Data \CustomerInterface::class)
60
+ ->disableOriginalConstructor ()
61
+ ->getMock ();
62
+
63
+ $ quoteMock = $ this ->getMockBuilder (\Magento \Quote \Model \Quote::class)
64
+ ->setMethods (['setCustomerEmail ' ])
65
+ ->disableOriginalConstructor ()
66
+ ->getMock ();
67
+
68
+ $ this ->eventMock ->expects ($ this ->any ())
69
+ ->method ('getCustomerDataObject ' )
70
+ ->will ($ this ->returnValue ($ customer ));
71
+ $ this ->eventMock ->expects ($ this ->any ())
72
+ ->method ('getOrigCustomerDataObject ' )
73
+ ->will ($ this ->returnValue ($ customerOrig ));
74
+
75
+ $ customer ->expects ($ this ->any ())
76
+ ->method ('getEmail ' )
77
+ ->willReturn ($ this ->returnValue ($ email ));
78
+ $ customerOrig ->expects ($ this ->any ())
79
+ ->method ('getEmail ' )
80
+ ->willReturn ($ this ->returnValue ($ origEmail ));
81
+
82
+ $ this ->quoteRepositoryMock ->expects ($ this ->once ())
83
+ ->method ('getForCustomer ' )
84
+ ->willReturn ($ quoteMock );
85
+
86
+ $ quoteMock ->expects ($ this ->once ())
87
+ ->method ('setCustomerEmail ' );
88
+
89
+ $ this ->quoteRepositoryMock ->expects ($ this ->once ())
90
+ ->method ('save ' )
91
+ ->with ($ quoteMock );
92
+
93
+ $ this ->model ->execute ($ this ->observerMock );
94
+ }
95
+ }
0 commit comments