-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
Copy pathTimezoneScopeTest.php
134 lines (116 loc) · 3.36 KB
/
TimezoneScopeTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
declare(strict_types=1);
/**
* Copyright 2015 Adobe
* All Rights Reserved.
*/
namespace Magento\Framework\Stdlib\Test\Unit\DateTime;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\ScopeInterface;
use Magento\Framework\App\ScopeResolverInterface;
use Magento\Framework\Locale\ResolverInterface;
use Magento\Framework\Stdlib\DateTime;
use Magento\Framework\Stdlib\DateTime\Intl\DateFormatterFactory;
use Magento\Framework\Stdlib\DateTime\Timezone;
use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
/**
* Test for scope date interval functionality @see Timezone
*/
class TimezoneScopeTest extends TestCase
{
/**
* @var string|null
*/
private ?string $defaultTimeZone;
/**
* @var string
*/
private string $scopeType = 'store';
/**
* @var string
*/
private string $defaultTimezonePath = 'default/timezone/path';
/**
* @var ScopeResolverInterface|MockObject
*/
private ScopeResolverInterface|MockObject $scopeResolver;
/**
* @var ScopeConfigInterface|MockObject
*/
private MockObject|ScopeConfigInterface $scopeConfig;
/**
* @var ResolverInterface|MockObject
*/
private ResolverInterface|MockObject $localeResolver;
/**
* @inheritdoc
*/
protected function setUp(): void
{
$this->defaultTimeZone = date_default_timezone_get();
date_default_timezone_set('UTC');
$this->scopeType = 'store';
$this->defaultTimezonePath = 'default/timezone/path';
$this->scopeResolver = $this->getMockBuilder(ScopeResolverInterface::class)
->getMock();
$this->localeResolver = $this->getMockBuilder(ResolverInterface::class)
->getMock();
$this->scopeConfig = $this->getMockBuilder(ScopeConfigInterface::class)
->getMock();
}
/**
* @inheritdoc
*/
protected function tearDown(): void
{
date_default_timezone_set($this->defaultTimeZone);
}
/**
* @return Timezone
* @throws Exception
*/
private function getTimezone(): Timezone
{
return new Timezone(
$this->scopeResolver,
$this->localeResolver,
$this->createMock(DateTime::class),
$this->scopeConfig,
$this->scopeType,
$this->defaultTimezonePath,
new DateFormatterFactory()
);
}
/**
* @return void
* @throws Exception
*/
public function testIsScopeDateInInterval()
{
$scopeMock = $this->createMock(ScopeInterface::class);
$this->scopeResolver->method('getScope')->willReturn($scopeMock);
$result = $this->getTimezone()->isScopeDateInInterval(
null,
'2025-04-01 00:00:00',
'2999-05-01 00:00:00',
);
$this->assertTrue($result);
}
/**
* @return void
* @throws Exception
*/
public function testIsScopeDateInIntervalFalse()
{
$scopeMock = $this->createMock(ScopeInterface::class);
$this->scopeResolver->method('getScope')->willReturn($scopeMock);
$result = $this->getTimezone()->isScopeDateInInterval(
null,
'2025-03-01 00:00:00',
'2025-04-01 00:00:00',
);
$this->assertFalse($result);
}
}