-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCarbonFiscalYearTest.php
44 lines (32 loc) · 1.58 KB
/
CarbonFiscalYearTest.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
<?php
use LaracraftTech\CarbonExtensions\CarbonFiscalYear;
use LaracraftTech\CarbonExtensions\CarbonFiscalYearImmutable;
it('can detect fiscal year start and end', function () {
// Let's test both instances...
foreach ([CarbonFiscalYear::class, CarbonFiscalYearImmutable::class] as $dateClass) {
/** @var CarbonFiscalYear|CarbonFiscalYearImmutable $dateClass */
//set fiscal year
$dateClass::setFiscalYearStart(4, 1);
$date = $dateClass::parse("2022-03-30");
expect($date->startOfYear()->format("Y-m-d"))->toBe("2021-04-01")
->and($date->endOfYear()->format("Y-m-d"))->toBe("2022-03-31");
$date = $dateClass::parse("2022-04-02");
expect($date->startOfYear()->format("Y-m-d"))->toBe("2022-04-01")
->and($date->endOfYear()->format("Y-m-d"))->toBe("2023-03-31");
//another fiscal year
$dateClass::setFiscalYearStart(10, 1);
$date = $dateClass::parse("2023-05-11");
expect($date->startOfYear()->format("Y-m-d"))->toBe("2022-10-01")
->and($date->endOfYear()->format("Y-m-d"))->toBe("2023-09-30");
}
});
it('works with im/mutable', function () {
CarbonFiscalYear::setFiscalYearStart(4, 1);
$mutableDate = CarbonFiscalYear::parse("2022-03-30");
$mutableDate2 = $mutableDate->addYear();
expect($mutableDate)->toBe($mutableDate2);
CarbonFiscalYearImmutable::setFiscalYearStart(4, 1);
$immutableDate = CarbonFiscalYearImmutable::parse("2022-03-30");
$immutableDate2 = $immutableDate->addYear();
expect($immutableDate)->not->toBe($immutableDate2);
});