Skip to content

Commit 46f9d7a

Browse files
author
Art Kurbakov
committed
Added tests for closures due to weather, emergencies and proclamations
1 parent 2713e27 commit 46f9d7a

9 files changed

Lines changed: 694 additions & 10 deletions

File tree

phpunit.xml.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,5 +199,9 @@
199199
<testsuite name="USA">
200200
<directory>./tests/USA</directory>
201201
</testsuite>
202+
<!-- Test Suite for holidays and closures of the New York Stock Exchange (NYSE) in United States -->
203+
<testsuite name="NYSE">
204+
<directory>./tests/USA/NYSE</directory>
205+
</testsuite>
202206
</testsuites>
203207
</phpunit>

src/Yasumi/Provider/USA/NYSE.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Yasumi\Provider\USA;
2626
use Yasumi\Holiday;
2727
use DateTime;
28+
use DateTimeZone;
2829

2930
class NYSE extends USA
3031
{
@@ -61,31 +62,31 @@ public function initialize(): void
6162
private function addWeatherEvents()
6263
{
6364
if (2012 == $this->year) {
64-
$this->addHoliday(new Holiday('hurricaneSandy1', [], new DateTime('2012-10-29')));
65-
$this->addHoliday(new Holiday('hurricaneSandy2', [], new DateTime('2012-10-30')));
65+
$this->addHoliday(new Holiday('hurricaneSandy1', [], new DateTime('2012-10-29', new DateTimeZone($this->timezone))));
66+
$this->addHoliday(new Holiday('hurricaneSandy2', [], new DateTime('2012-10-30', new DateTimeZone($this->timezone))));
6667
}
6768
}
6869

6970
private function addEmergencies()
7071
{
7172
if (2001 == $this->year) {
72-
$this->addHoliday(new Holiday('WTCAttack1', [], new DateTime('2001-09-11')));
73-
$this->addHoliday(new Holiday('WTCAttack2', [], new DateTime('2001-09-12')));
74-
$this->addHoliday(new Holiday('WTCAttack3', [], new DateTime('2001-09-13')));
75-
$this->addHoliday(new Holiday('WTCAttack4', [], new DateTime('2001-09-14')));
73+
$this->addHoliday(new Holiday('groundZero1', [], new DateTime('2001-09-11', new DateTimeZone($this->timezone))));
74+
$this->addHoliday(new Holiday('groundZero2', [], new DateTime('2001-09-12', new DateTimeZone($this->timezone))));
75+
$this->addHoliday(new Holiday('groundZero3', [], new DateTime('2001-09-13', new DateTimeZone($this->timezone))));
76+
$this->addHoliday(new Holiday('groundZero4', [], new DateTime('2001-09-14', new DateTimeZone($this->timezone))));
7677
}
7778
}
7879

7980
private function addProclamations()
8081
{
8182
if (2004 == $this->year)
82-
$this->addHoliday(new Holiday('ReaganMourning', [], new DateTime('2004-06-11')));
83+
$this->addHoliday(new Holiday('ReaganMourning', [], new DateTime('2004-06-11', new DateTimeZone($this->timezone))));
8384
if (2007 == $this->year)
84-
$this->addHoliday(new Holiday('GRFordMourning', [], new DateTime('2007-01-02')));
85+
$this->addHoliday(new Holiday('GRFordMourning', [], new DateTime('2007-01-02', new DateTimeZone($this->timezone))));
8586
if (2018 == $this->year)
86-
$this->addHoliday(new Holiday('HWBushMourning', [], new DateTime('2018-12-05')));
87+
$this->addHoliday(new Holiday('HWBushMourning', [], new DateTime('2018-12-05', new DateTimeZone($this->timezone))));
8788
if (2025 == $this->year)
88-
$this->addHoliday(new Holiday('CarterMourning', [], new DateTime('2025-01-09')));
89+
$this->addHoliday(new Holiday('CarterMourning', [], new DateTime('2025-01-09', new DateTimeZone($this->timezone))));
8990
}
9091

9192
public function getSources(): array
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
/**
6+
* This file is part of the 'Yasumi' package.
7+
*
8+
* The easy PHP Library for calculating holidays.
9+
*
10+
* Copyright (c) 2025 Magic Web Group
11+
*
12+
* For the full copyright and license information, please view the LICENSE
13+
* file that was distributed with this source code.
14+
*
15+
* @author Art Kurbakov <admin at mgwebgroup dot com>
16+
*/
17+
18+
namespace Yasumi\tests\USA\NYSE;
19+
20+
use Yasumi\Holiday;
21+
use Yasumi\tests\HolidayTestCase;
22+
use Yasumi\tests\USA\USABaseTestCase;
23+
use DateTime;
24+
use DateTimeZone;
25+
26+
/**
27+
* Class to test day of closure of NYSE due to Jimmy Carter mourning proclamation
28+
*/
29+
class CarterMourningTest extends USABaseTestCase
30+
{
31+
/**
32+
* Name of provider to be tested.
33+
*/
34+
public const REGION = 'USA/NYSE';
35+
36+
/**
37+
* The year when the closure was observed.
38+
*/
39+
public const OBSERVED_YEAR = 2025;
40+
41+
/**
42+
* Tests day of closure on January 9th 2025
43+
*
44+
* @throws \Exception
45+
*/
46+
public function testCarterMourning(): void
47+
{
48+
$this->assertHoliday(
49+
self::REGION,
50+
'CarterMourning',
51+
self::OBSERVED_YEAR,
52+
new DateTime("2025-01-09", new DateTimeZone(self::TIMEZONE))
53+
);
54+
}
55+
56+
/**
57+
* Tests years before 2025
58+
*
59+
* @throws \Exception
60+
*/
61+
public function testCarterMourningBefore2025(): void
62+
{
63+
$this->assertNotHoliday(
64+
self::REGION,
65+
'CarterMourning',
66+
self::OBSERVED_YEAR - 1
67+
);
68+
}
69+
70+
/**
71+
* Tests years after 2025
72+
*
73+
* @throws \Exception
74+
*/
75+
public function testCarterMourningAfter2025(): void
76+
{
77+
$this->assertNotHoliday(
78+
self::REGION,
79+
'CarterMourning',
80+
self::OBSERVED_YEAR + 1
81+
);
82+
}
83+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
/**
6+
* This file is part of the 'Yasumi' package.
7+
*
8+
* The easy PHP Library for calculating holidays.
9+
*
10+
* Copyright (c) 2025 Magic Web Group
11+
*
12+
* For the full copyright and license information, please view the LICENSE
13+
* file that was distributed with this source code.
14+
*
15+
* @author Art Kurbakov <admin at mgwebgroup dot com>
16+
*/
17+
18+
namespace Yasumi\tests\USA\NYSE;
19+
20+
use Yasumi\Holiday;
21+
use Yasumi\tests\HolidayTestCase;
22+
use Yasumi\tests\USA\USABaseTestCase;
23+
use DateTime;
24+
use DateTimeZone;
25+
26+
/**
27+
* Class to test day of closure of NYSE due to G.R. Ford Mourning proclamation
28+
*/
29+
class GRFordMourningTest extends USABaseTestCase
30+
{
31+
/**
32+
* Name of provider to be tested.
33+
*/
34+
public const REGION = 'USA/NYSE';
35+
36+
/**
37+
* The year when the closure was observed.
38+
*/
39+
public const OBSERVED_YEAR = 2007;
40+
41+
/**
42+
* Tests day of closure on January 2nd 2007
43+
*
44+
* @throws \Exception
45+
*/
46+
public function testGRFordMourning(): void
47+
{
48+
$this->assertHoliday(
49+
self::REGION,
50+
'GRFordMourning',
51+
self::OBSERVED_YEAR,
52+
new DateTime("2007-01-02", new DateTimeZone(self::TIMEZONE))
53+
);
54+
}
55+
56+
/**
57+
* Tests years before 2007
58+
*
59+
* @throws \Exception
60+
*/
61+
public function testGRFordMourningBefore2007(): void
62+
{
63+
$this->assertNotHoliday(
64+
self::REGION,
65+
'GRFordMourning',
66+
self::OBSERVED_YEAR - 1
67+
);
68+
}
69+
70+
/**
71+
* Tests years after 2007
72+
*
73+
* @throws \Exception
74+
*/
75+
public function testGRFordMourningAfter2007(): void
76+
{
77+
$this->assertNotHoliday(
78+
self::REGION,
79+
'GRFordMourning',
80+
self::OBSERVED_YEAR + 1
81+
);
82+
}
83+
}

tests/USA/NYSE/GroundZeroTest.php

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
/**
6+
* This file is part of the 'Yasumi' package.
7+
*
8+
* The easy PHP Library for calculating holidays.
9+
*
10+
* Copyright (c) 2025 Magic Web Group
11+
*
12+
* For the full copyright and license information, please view the LICENSE
13+
* file that was distributed with this source code.
14+
*
15+
* @author Art Kurbakov <admin at mgwebgroup dot com>
16+
*/
17+
18+
namespace Yasumi\tests\USA\NYSE;
19+
20+
use Yasumi\Holiday;
21+
use Yasumi\tests\HolidayTestCase;
22+
use Yasumi\tests\USA\USABaseTestCase;
23+
use DateTime;
24+
use DateTimeZone;
25+
26+
/**
27+
* Class to test 4 days of closure of NYSE due to September 11th attacks
28+
*/
29+
class GroundZeroTest extends USABaseTestCase
30+
{
31+
/**
32+
* Name of provider to be tested.
33+
*/
34+
public const REGION = 'USA/NYSE';
35+
36+
/**
37+
* The year when the closure was observed.
38+
*/
39+
public const OBSERVED_YEAR = 2001;
40+
41+
/**
42+
* Tests 4 days of closure on September 11th 2001
43+
*
44+
* @throws \Exception
45+
*/
46+
public function testGroundZero(): void
47+
{
48+
$this->assertHoliday(
49+
self::REGION,
50+
'groundZero1',
51+
self::OBSERVED_YEAR,
52+
new DateTime("2001-09-11", new DateTimeZone(self::TIMEZONE))
53+
);
54+
55+
$this->assertHoliday(
56+
self::REGION,
57+
'groundZero2',
58+
self::OBSERVED_YEAR,
59+
new DateTime("2001-09-12", new DateTimeZone(self::TIMEZONE))
60+
);
61+
62+
$this->assertHoliday(
63+
self::REGION,
64+
'groundZero3',
65+
self::OBSERVED_YEAR,
66+
new DateTime("2001-09-13", new DateTimeZone(self::TIMEZONE))
67+
);
68+
69+
$this->assertHoliday(
70+
self::REGION,
71+
'groundZero4',
72+
self::OBSERVED_YEAR,
73+
new DateTime("2001-09-14", new DateTimeZone(self::TIMEZONE))
74+
);
75+
}
76+
77+
/**
78+
* Tests years before 2001
79+
*
80+
* @throws \Exception
81+
*/
82+
public function testGroundZeroBefore2001(): void
83+
{
84+
$this->assertNotHoliday(
85+
self::REGION,
86+
'groundZero1',
87+
self::OBSERVED_YEAR - 1
88+
);
89+
90+
$this->assertNotHoliday(
91+
self::REGION,
92+
'groundZero2',
93+
self::OBSERVED_YEAR - 1
94+
);
95+
96+
$this->assertNotHoliday(
97+
self::REGION,
98+
'groundZero3',
99+
self::OBSERVED_YEAR - 1
100+
);
101+
102+
$this->assertNotHoliday(
103+
self::REGION,
104+
'groundZero4',
105+
self::OBSERVED_YEAR - 1
106+
);
107+
}
108+
109+
/**
110+
* Tests years after 2001
111+
*
112+
* @throws \Exception
113+
*/
114+
public function testGroundZeroAfter2001(): void
115+
{
116+
$this->assertNotHoliday(
117+
self::REGION,
118+
'groundZero1',
119+
self::OBSERVED_YEAR + 1
120+
);
121+
122+
$this->assertNotHoliday(
123+
self::REGION,
124+
'groundZero2',
125+
self::OBSERVED_YEAR + 1
126+
);
127+
128+
$this->assertNotHoliday(
129+
self::REGION,
130+
'groundZero3',
131+
self::OBSERVED_YEAR + 1
132+
);
133+
134+
$this->assertNotHoliday(
135+
self::REGION,
136+
'groundZero4',
137+
self::OBSERVED_YEAR + 1
138+
);
139+
}
140+
}

0 commit comments

Comments
 (0)