7
7
8
8
namespace Magento \Sales \Test \Unit \Model ;
9
9
10
+ use Magento \Config \Model \Config \Backend \Encrypted ;
10
11
use Magento \Framework \App \Config ;
12
+ use Magento \Framework \App \Config \Value ;
13
+ use Magento \Framework \App \Config \ValueFactory ;
11
14
use Magento \Framework \DB \Select ;
15
+ use Magento \Framework \Stdlib \DateTime \TimezoneInterface ;
12
16
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
13
17
use Magento \Sales \Model \AbstractModel ;
14
18
use Magento \Sales \Model \EmailSenderHandler ;
@@ -71,6 +75,16 @@ class EmailSenderHandlerTest extends TestCase
71
75
*/
72
76
private $ storeManagerMock ;
73
77
78
+ /**
79
+ * @var ValueFactory|MockObject
80
+ */
81
+ private $ configValueFactory ;
82
+
83
+ /**
84
+ * @var TimezoneInterface|MockObject
85
+ */
86
+ private $ localeDate ;
87
+
74
88
protected function setUp (): void
75
89
{
76
90
$ objectManager = new ObjectManager ($ this );
@@ -110,15 +124,25 @@ protected function setUp(): void
110
124
StoreManagerInterface::class
111
125
);
112
126
127
+ $ this ->configValueFactory = $ this ->createMock (
128
+ ValueFactory::class
129
+ );
130
+
131
+ $ this ->localeDate = $ this ->createMock (
132
+ TimezoneInterface::class
133
+ );
134
+
113
135
$ this ->object = $ objectManager ->getObject (
114
136
EmailSenderHandler::class,
115
137
[
116
- 'emailSender ' => $ this ->emailSender ,
117
- 'entityResource ' => $ this ->entityResource ,
118
- 'entityCollection ' => $ this ->entityCollection ,
119
- 'globalConfig ' => $ this ->globalConfig ,
120
- 'identityContainer ' => $ this ->identityContainerMock ,
121
- 'storeManager ' => $ this ->storeManagerMock ,
138
+ 'emailSender ' => $ this ->emailSender ,
139
+ 'entityResource ' => $ this ->entityResource ,
140
+ 'entityCollection ' => $ this ->entityCollection ,
141
+ 'globalConfig ' => $ this ->globalConfig ,
142
+ 'identityContainer ' => $ this ->identityContainerMock ,
143
+ 'storeManager ' => $ this ->storeManagerMock ,
144
+ 'configValueFactory ' => $ this ->configValueFactory ,
145
+ 'localeDate ' => $ this ->localeDate ,
122
146
]
123
147
);
124
148
}
@@ -151,6 +175,14 @@ public function testExecute($configValue, $collectionItems, $emailSendingResult)
151
175
->method ('addFieldToFilter ' )
152
176
->with ('email_sent ' , ['null ' => true ]);
153
177
178
+ $ dateTime = new \DateTime ();
179
+ $ nowDate = $ dateTime ->format ('Y-m-d H:i:s ' );
180
+ $ fromDate = $ dateTime ->modify ('-1 day ' )->format ('Y-m-d H:i:s ' );
181
+ $ this ->entityCollection
182
+ ->expects ($ this ->at (2 ))
183
+ ->method ('addFieldToFilter ' )
184
+ ->with ('created_at ' , ['from ' => $ fromDate ]);
185
+
154
186
$ this ->entityCollection
155
187
->expects ($ this ->any ())
156
188
->method ('addAttributeToSelect ' )
@@ -175,6 +207,24 @@ public function testExecute($configValue, $collectionItems, $emailSendingResult)
175
207
->method ('getItems ' )
176
208
->willReturn ($ collectionItems );
177
209
210
+ /** @var Value|Encrypted|MockObject $valueMock */
211
+ $ backendModelMock = $ this ->getMockBuilder (Value::class)
212
+ ->disableOriginalConstructor ()
213
+ ->onlyMethods (['load ' , 'getId ' ])
214
+ ->addMethods (['getUpdatedAt ' ])
215
+ ->getMock ();
216
+ $ backendModelMock ->expects ($ this ->once ())->method ('load ' )->willReturnSelf ();
217
+ $ backendModelMock ->expects ($ this ->once ())->method ('getId ' )->willReturn (1 );
218
+ $ backendModelMock ->expects ($ this ->once ())->method ('getUpdatedAt ' )->willReturn ($ nowDate );
219
+
220
+ $ this ->configValueFactory ->expects ($ this ->once ())
221
+ ->method ('create ' )
222
+ ->willReturn ($ backendModelMock );
223
+
224
+ $ this ->localeDate ->expects ($ this ->exactly (2 ))
225
+ ->method ('date ' )
226
+ ->willReturn (new \DateTime ($ nowDate ));
227
+
178
228
if ($ collectionItems ) {
179
229
180
230
/** @var AbstractModel|MockObject $collectionItem */
0 commit comments