7
7
8
8
namespace Magento \Persistent \Test \Unit \Model \ResourceModel ;
9
9
10
+ use Magento \Framework \DB \Adapter \AdapterInterface ;
10
11
use Magento \Persistent \Model \ResourceModel \ExpiredPersistentQuotesCollection ;
11
12
use Magento \Quote \Model \ResourceModel \Quote \CollectionFactory ;
12
13
use Magento \Framework \App \Config \ScopeConfigInterface ;
@@ -65,35 +66,6 @@ public function testGetExpiredPersistentQuotes(): void
65
66
$ quoteCollectionMock = $ this ->createMock (Collection::class);
66
67
$ this ->quoteCollectionFactoryMock ->method ('create ' )->willReturn ($ quoteCollectionMock );
67
68
68
- $ dbSelectMock = $ this ->createMock (Select::class);
69
- $ quoteCollectionMock ->method ('getSelect ' )->willReturn ($ dbSelectMock );
70
- $ quoteCollectionMock ->method ('getTable ' )->willReturn ('customer_log ' );
71
-
72
- $ dbSelectMock ->method ('joinLeft ' )
73
- ->willReturnCallback (function ($ table , $ condition ) use ($ dbSelectMock ) {
74
- static $ callCount = 0 ;
75
- $ callCount ++;
76
-
77
- if ($ callCount === 1 ) {
78
- $ this ->assertEquals (['cl1 ' => 'customer_log ' ], $ table );
79
- $ this ->assertStringContainsString ('cl1.customer_id = main_table.customer_id ' , $ condition );
80
- $ this ->assertStringContainsString ('cl1.last_login_at < cl1.last_logout_at ' , $ condition );
81
- $ this ->assertStringContainsString ('cl1.last_logout_at IS NOT NULL ' , $ condition );
82
- }
83
-
84
- if ($ callCount === 2 ) {
85
- $ this ->assertEquals (['cl2 ' => 'customer_log ' ], $ table );
86
- $ this ->assertStringContainsString ('cl2.customer_id = main_table.customer_id ' , $ condition );
87
- $ this ->assertStringContainsString ('cl2.last_login_at < ' , $ condition );
88
- $ this ->assertStringContainsString (
89
- 'cl2.last_logout_at IS NULL OR cl2.last_login_at > cl2.last_logout_at ' ,
90
- $ condition
91
- );
92
- }
93
-
94
- return $ dbSelectMock ;
95
- });
96
-
97
69
$ quoteCollectionMock ->method ('addFieldToFilter ' )
98
70
->willReturnCallback (function ($ field ) use ($ quoteCollectionMock ) {
99
71
static $ filterCallCount = 0 ;
@@ -117,6 +89,58 @@ public function testGetExpiredPersistentQuotes(): void
117
89
->with ($ this ->isType ('integer ' ))
118
90
->willReturnSelf ();
119
91
92
+ $ dbSelectMock1 = $ this ->createMock (Select::class);
93
+ $ dbSelectMock2 = $ this ->createMock (Select::class);
94
+ $ dbSelectMock3 = $ this ->createMock (Select::class);
95
+ $ quoteCollectionMock ->method ('getSelect ' )
96
+ ->willReturnOnConsecutiveCalls ($ dbSelectMock1 , $ dbSelectMock2 , $ dbSelectMock3 );
97
+ $ quoteCollectionMock ->method ('getTable ' )
98
+ ->willReturn ('customer_log ' );
99
+
100
+ $ dbSelectMock1 ->method ('reset ' )
101
+ ->with (Select::COLUMNS )
102
+ ->willReturn ($ dbSelectMock1 );
103
+ $ dbSelectMock1 ->method ('columns ' )->willReturnSelf ();
104
+ $ dbSelectMock1 ->method ('joinLeft ' )
105
+ ->with (
106
+ ['cl1 ' => 'customer_log ' ],
107
+ 'cl1.customer_id = main_table.customer_id ' ,
108
+ []
109
+ )
110
+ ->willReturnSelf ();
111
+ $ dbSelectMock1 ->method ('where ' )
112
+ ->with ('cl1.last_login_at < cl1.last_logout_at
113
+ AND cl1.last_logout_at IS NOT NULL ' )
114
+ ->willReturnSelf ();
115
+
116
+ $ dbSelectMock2 ->method ('reset ' )
117
+ ->with (Select::COLUMNS )
118
+ ->willReturn ($ dbSelectMock2 );
119
+ $ dbSelectMock2 ->method ('columns ' )->willReturnSelf ();
120
+ $ dbSelectMock2 ->method ('joinLeft ' )
121
+ ->with (
122
+ ['cl2 ' => 'customer_log ' ],
123
+ 'cl2.customer_id = main_table.customer_id ' ,
124
+ []
125
+ )
126
+ ->willReturnSelf ();
127
+ $ dbSelectMock2 ->method ('where ' )
128
+ ->with ('cl2.last_login_at < " ' . gmdate ("Y-m-d H:i:s " , time () - 60 ) . '"
129
+ AND (cl2.last_logout_at IS NULL OR cl2.last_login_at > cl2.last_logout_at) ' )
130
+ ->willReturnSelf ();
131
+
132
+ $ dbSelectMockUnion = $ this ->createMock (Select::class);
133
+ $ connectionMock = $ this ->createMock (AdapterInterface::class);
134
+ $ quoteCollectionMock ->method ('getConnection ' )->willReturn ($ connectionMock );
135
+ $ connectionMock ->method ('select ' )->willReturn ($ dbSelectMockUnion );
136
+ $ dbSelectMockUnion ->method ('union ' )
137
+ ->with ([$ dbSelectMock1 , $ dbSelectMock2 ], Select::SQL_UNION_ALL )
138
+ ->willReturn ($ dbSelectMockUnion );
139
+
140
+ $ dbSelectMockUnion ->method ('where ' )
141
+ ->with ($ this ->stringContains ('main_table.entity_id IN ( ' ))
142
+ ->willReturnSelf ();
143
+
120
144
$ result = $ this ->model ->getExpiredPersistentQuotes ($ storeMock , 0 , 100 );
121
145
$ this ->assertSame ($ quoteCollectionMock , $ result );
122
146
}
0 commit comments