10
10
use Magento \Framework \DB \Adapter \AdapterInterface as ConnectionAdapterInterface ;
11
11
use Magento \Framework \DB \Select ;
12
12
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
13
+ use Magento \Sales \Model \Grid \LastUpdateTimeCache ;
13
14
use Magento \Sales \Model \ResourceModel \Grid ;
14
15
use Magento \Sales \Model \ResourceModel \Provider \NotSyncedDataProviderInterface ;
15
16
use PHPUnit \Framework \MockObject \MockObject ;
@@ -59,14 +60,9 @@ class GridTest extends TestCase
59
60
protected function setUp (): void
60
61
{
61
62
$ objectManager = new ObjectManager ($ this );
62
- $ this ->notSyncedDataProvider = $ this ->getMockBuilder (NotSyncedDataProviderInterface::class)
63
- ->disableOriginalConstructor ()
64
- ->setMethods (['getIds ' ])
65
- ->getMockForAbstractClass ();
66
- $ this ->connection = $ this ->getMockBuilder (ConnectionAdapterInterface::class)
67
- ->disableOriginalConstructor ()
68
- ->setMethods (['select ' , 'fetchAll ' , 'insertOnDuplicate ' ])
69
- ->getMockForAbstractClass ();
63
+ $ this ->notSyncedDataProvider = $ this ->createMock (NotSyncedDataProviderInterface::class);
64
+ $ this ->connection = $ this ->createMock (ConnectionAdapterInterface::class);
65
+ $ lastUpdateTimeCache = $ this ->createMock (LastUpdateTimeCache::class);
70
66
71
67
$ this ->grid = $ objectManager ->getObject (
72
68
Grid::class,
@@ -76,7 +72,8 @@ protected function setUp(): void
76
72
'gridTableName ' => $ this ->gridTable ,
77
73
'connection ' => $ this ->connection ,
78
74
'_tables ' => ['sales_order ' => $ this ->mainTable , 'sales_order_grid ' => $ this ->gridTable ],
79
- 'columns ' => $ this ->columns
75
+ 'columns ' => $ this ->columns ,
76
+ 'lastUpdateTimeCache ' => $ lastUpdateTimeCache ,
80
77
]
81
78
);
82
79
}
@@ -87,23 +84,36 @@ protected function setUp(): void
87
84
public function testRefreshBySchedule ()
88
85
{
89
86
$ notSyncedIds = ['1 ' , '2 ' , '3 ' ];
90
- $ fetchResult = ['column_1 ' => '1 ' , 'column_2 ' => '2 ' ];
87
+ $ fetchResult = [
88
+ ['entity_id ' => 1 , 'updated_at ' => date ('Y-m-d H:i:s ' )],
89
+ ['entity_id ' => 2 , 'updated_at ' => date ('Y-m-d H:i:s ' )],
90
+ ];
91
91
92
- $ this ->notSyncedDataProvider ->expects ($ this ->atLeastOnce ())->method ('getIds ' )->willReturn ($ notSyncedIds );
93
- $ select = $ this ->getMockBuilder (Select::class)
94
- ->disableOriginalConstructor ()
95
- ->setMethods (['from ' , 'columns ' , 'where ' ])
96
- ->getMock ();
97
- $ select ->expects ($ this ->atLeastOnce ())->method ('from ' )->with (['sales_order ' => $ this ->mainTable ], [])
92
+ $ this ->notSyncedDataProvider ->expects ($ this ->atLeastOnce ())
93
+ ->method ('getIds ' )
94
+ ->willReturn ($ notSyncedIds );
95
+ $ select = $ this ->createMock (Select::class);
96
+ $ select ->expects ($ this ->atLeastOnce ())
97
+ ->method ('from ' )
98
+ ->with (['sales_order ' => $ this ->mainTable ], [])
98
99
->willReturnSelf ();
99
- $ select ->expects ($ this ->atLeastOnce ())->method ('columns ' )->willReturnSelf ();
100
- $ select ->expects ($ this ->atLeastOnce ())->method ('where ' )
100
+ $ select ->expects ($ this ->atLeastOnce ())
101
+ ->method ('columns ' )
102
+ ->willReturnSelf ();
103
+ $ select ->expects ($ this ->atLeastOnce ())
104
+ ->method ('where ' )
101
105
->with ($ this ->mainTable . '.entity_id IN (?) ' , $ notSyncedIds )
102
106
->willReturnSelf ();
103
107
104
- $ this ->connection ->expects ($ this ->atLeastOnce ())->method ('select ' )->willReturn ($ select );
105
- $ this ->connection ->expects ($ this ->atLeastOnce ())->method ('fetchAll ' )->with ($ select )->willReturn ($ fetchResult );
106
- $ this ->connection ->expects ($ this ->atLeastOnce ())->method ('insertOnDuplicate ' )
108
+ $ this ->connection ->expects ($ this ->atLeastOnce ())
109
+ ->method ('select ' )
110
+ ->willReturn ($ select );
111
+ $ this ->connection ->expects ($ this ->atLeastOnce ())
112
+ ->method ('fetchAll ' )
113
+ ->with ($ select )
114
+ ->willReturn ($ fetchResult );
115
+ $ this ->connection ->expects ($ this ->atLeastOnce ())
116
+ ->method ('insertOnDuplicate ' )
107
117
->with ($ this ->gridTable , $ fetchResult , array_keys ($ this ->columns ))
108
118
->willReturn (array_count_values ($ notSyncedIds ));
109
119
0 commit comments