11
11
use Magento \CatalogRule \Model \Indexer \ReindexRuleProductPrice ;
12
12
use Magento \CatalogRule \Model \Indexer \RuleProductPricesPersistor ;
13
13
use Magento \CatalogRule \Model \Indexer \RuleProductsSelectBuilder ;
14
- use Magento \Framework \Stdlib \DateTime \DateTime ;
15
14
use Magento \Framework \Stdlib \DateTime \TimezoneInterface ;
16
15
use Magento \Store \Api \Data \GroupInterface ;
17
16
use Magento \Store \Api \Data \WebsiteInterface ;
@@ -41,65 +40,60 @@ class ReindexRuleProductPriceTest extends \PHPUnit\Framework\TestCase
41
40
private $ productPriceCalculatorMock ;
42
41
43
42
/**
44
- * @var DateTime |MockObject
43
+ * @var TimezoneInterface |MockObject
45
44
*/
46
- private $ dateTimeMock ;
45
+ private $ localeDate ;
47
46
48
47
/**
49
48
* @var RuleProductPricesPersistor|MockObject
50
49
*/
51
50
private $ pricesPersistorMock ;
52
51
53
- /**
54
- * @var TimezoneInterface|MockObject
55
- */
56
- private $ localeDate ;
57
-
58
52
protected function setUp ()
59
53
{
60
54
$ this ->storeManagerMock = $ this ->createMock (StoreManagerInterface::class);
61
55
$ this ->ruleProductsSelectBuilderMock = $ this ->createMock (RuleProductsSelectBuilder::class);
62
56
$ this ->productPriceCalculatorMock = $ this ->createMock (ProductPriceCalculator::class);
63
- $ this ->dateTimeMock = $ this ->createMock (DateTime::class);
64
- $ this ->pricesPersistorMock = $ this ->createMock (RuleProductPricesPersistor::class);
65
57
$ this ->localeDate = $ this ->createMock (TimezoneInterface::class);
58
+ $ this ->pricesPersistorMock = $ this ->createMock (RuleProductPricesPersistor::class);
66
59
67
60
$ this ->model = new ReindexRuleProductPrice (
68
61
$ this ->storeManagerMock ,
69
62
$ this ->ruleProductsSelectBuilderMock ,
70
63
$ this ->productPriceCalculatorMock ,
71
- $ this ->dateTimeMock ,
72
- $ this ->pricesPersistorMock ,
73
- $ this ->localeDate
64
+ $ this ->localeDate ,
65
+ $ this ->pricesPersistorMock
74
66
);
75
67
}
76
68
77
69
public function testExecute ()
78
70
{
79
71
$ websiteId = 234 ;
80
- $ storeGroupId = 30 ;
81
- $ storeId = 40 ;
82
- $ productMock = $ this ->createMock (Product::class);
72
+ $ defaultGroupId = 11 ;
73
+ $ defaultStoreId = 22 ;
83
74
84
75
$ websiteMock = $ this ->createMock (WebsiteInterface::class);
85
76
$ websiteMock ->expects ($ this ->once ())
86
77
->method ('getId ' )
87
78
->willReturn ($ websiteId );
88
79
$ websiteMock ->expects ($ this ->once ())
89
80
->method ('getDefaultGroupId ' )
90
- ->willReturn ($ storeGroupId );
81
+ ->willReturn ($ defaultGroupId );
91
82
$ this ->storeManagerMock ->expects ($ this ->once ())
92
83
->method ('getWebsites ' )
93
84
->willReturn ([$ websiteMock ]);
94
- $ storeGroupMock = $ this ->createMock (GroupInterface::class);
95
- $ storeGroupMock ->expects ($ this ->once ())
85
+ $ groupMock = $ this ->createMock (GroupInterface::class);
86
+ $ groupMock ->method ('getId ' )
87
+ ->willReturn ($ defaultStoreId );
88
+ $ groupMock ->expects ($ this ->once ())
96
89
->method ('getDefaultStoreId ' )
97
- ->willReturn ($ storeId );
90
+ ->willReturn ($ defaultStoreId );
98
91
$ this ->storeManagerMock ->expects ($ this ->once ())
99
92
->method ('getGroup ' )
100
- ->with ($ storeGroupId )
101
- ->willReturn ($ storeGroupMock );
93
+ ->with ($ defaultGroupId )
94
+ ->willReturn ($ groupMock );
102
95
96
+ $ productMock = $ this ->createMock (Product::class);
103
97
$ statementMock = $ this ->createMock (\Zend_Db_Statement_Interface::class);
104
98
$ this ->ruleProductsSelectBuilderMock ->expects ($ this ->once ())
105
99
->method ('build ' )
@@ -115,22 +109,10 @@ public function testExecute()
115
109
'action_stop ' => true
116
110
];
117
111
118
- $ this ->dateTimeMock ->expects ($ this ->at (0 ))
119
- ->method ('date ' )
120
- ->with ('Y-m-d 00:00:00 ' , $ ruleData ['from_time ' ])
121
- ->willReturn ($ ruleData ['from_time ' ]);
122
- $ this ->dateTimeMock ->expects ($ this ->at (1 ))
123
- ->method ('timestamp ' )
124
- ->with ($ ruleData ['from_time ' ])
125
- ->willReturn ($ ruleData ['from_time ' ]);
126
- $ this ->dateTimeMock ->expects ($ this ->at (2 ))
127
- ->method ('date ' )
128
- ->with ('Y-m-d 00:00:00 ' , $ ruleData ['to_time ' ])
129
- ->willReturn ($ ruleData ['to_time ' ]);
130
- $ this ->dateTimeMock ->expects ($ this ->at (3 ))
131
- ->method ('timestamp ' )
132
- ->with ($ ruleData ['to_time ' ])
133
- ->willReturn ($ ruleData ['to_time ' ]);
112
+ $ this ->localeDate ->expects ($ this ->once ())
113
+ ->method ('scopeDate ' )
114
+ ->with ($ defaultStoreId , null , true )
115
+ ->willReturn (new \DateTime ());
134
116
135
117
$ statementMock ->expects ($ this ->at (0 ))
136
118
->method ('fetch ' )
0 commit comments