@@ -22,16 +22,33 @@ class ValidatorTest extends \PHPUnit\Framework\TestCase
22
22
*/
23
23
private $ validator ;
24
24
25
+ /**
26
+ * @var \PHPUnit\Framework\MockObject\MockObject|\Magento\Framework\Stdlib\DateTime\DateTime
27
+ */
28
+ private $ dateTimeMock ;
29
+
25
30
protected function setUp ()
26
31
{
27
32
$ objectManager = new ObjectManager ($ this );
28
- $ this ->validator = $ objectManager ->getObject (\Magento \Security \Model \UserExpiration \Validator::class);
33
+ $ this ->dateTimeMock =
34
+ $ this ->createPartialMock (\Magento \Framework \Stdlib \DateTime \DateTime::class, ['gmtTimestamp ' ]);
35
+ $ this ->validator = $ objectManager ->getObject (
36
+ \Magento \Security \Model \UserExpiration \Validator::class,
37
+ ['dateTime ' => $ this ->dateTimeMock ]
38
+ );
29
39
}
30
40
31
41
public function testWithPastDate ()
32
42
{
43
+ $ currentTime = '1562447687 ' ;
44
+ $ expireTime = '1561324487 ' ;
33
45
$ testDate = new \DateTime ();
34
46
$ testDate ->modify ('-10 days ' );
47
+ $ this ->dateTimeMock ->expects (static ::exactly (2 ))->method ('gmtTimestamp ' )
48
+ ->willReturnOnConsecutiveCalls (
49
+ $ currentTime ,
50
+ $ expireTime
51
+ );
35
52
static ::assertFalse ($ this ->validator ->isValid ($ testDate ->format ('Y-m-d H:i:s ' )));
36
53
static ::assertContains (
37
54
'"Expiration date" must be later than the current date. ' ,
@@ -41,8 +58,15 @@ public function testWithPastDate()
41
58
42
59
public function testWithFutureDate ()
43
60
{
61
+ $ currentTime = '1562447687 ' ;
62
+ $ expireTime = '1563290841 ' ;
44
63
$ testDate = new \DateTime ();
45
64
$ testDate ->modify ('+10 days ' );
65
+ $ this ->dateTimeMock ->expects (static ::exactly (2 ))->method ('gmtTimestamp ' )
66
+ ->willReturnOnConsecutiveCalls (
67
+ $ currentTime ,
68
+ $ expireTime
69
+ );
46
70
static ::assertTrue ($ this ->validator ->isValid ($ testDate ->format ('Y-m-d H:i:s ' )));
47
71
static ::assertEquals ([], $ this ->validator ->getMessages ());
48
72
}
0 commit comments