77
88namespace Magento \Persistent \Test \Unit \Model \ResourceModel ;
99
10+ use Magento \Framework \DB \Adapter \AdapterInterface ;
1011use Magento \Persistent \Model \ResourceModel \ExpiredPersistentQuotesCollection ;
1112use Magento \Quote \Model \ResourceModel \Quote \CollectionFactory ;
1213use Magento \Framework \App \Config \ScopeConfigInterface ;
@@ -65,35 +66,6 @@ public function testGetExpiredPersistentQuotes(): void
6566 $ quoteCollectionMock = $ this ->createMock (Collection::class);
6667 $ this ->quoteCollectionFactoryMock ->method ('create ' )->willReturn ($ quoteCollectionMock );
6768
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-
9769 $ quoteCollectionMock ->method ('addFieldToFilter ' )
9870 ->willReturnCallback (function ($ field ) use ($ quoteCollectionMock ) {
9971 static $ filterCallCount = 0 ;
@@ -117,6 +89,58 @@ public function testGetExpiredPersistentQuotes(): void
11789 ->with ($ this ->isType ('integer ' ))
11890 ->willReturnSelf ();
11991
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+
120144 $ result = $ this ->model ->getExpiredPersistentQuotes ($ storeMock , 0 , 100 );
121145 $ this ->assertSame ($ quoteCollectionMock , $ result );
122146 }
0 commit comments