forked from spatie/period
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoundaryTest.php
75 lines (59 loc) · 2.3 KB
/
BoundaryTest.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
<?php
namespace Spatie\Period\Tests;
use PHPUnit\Framework\TestCase;
use Spatie\Period\Boundaries;
use Spatie\Period\Period;
class BoundaryTest extends TestCase
{
/** @test */
public function exclude_none()
{
$period = Period::make('2018-01-01', '2018-01-31', null, Boundaries::EXCLUDE_NONE);
$this->assertFalse($period->startExcluded());
$this->assertFalse($period->endExcluded());
}
/** @test */
public function exclude_start()
{
$period = Period::make('2018-01-01', '2018-01-31', null, Boundaries::EXCLUDE_START);
$this->assertTrue($period->startExcluded());
$this->assertFalse($period->endExcluded());
}
/** @test */
public function exclude_end()
{
$period = Period::make('2018-01-01', '2018-01-31', null, Boundaries::EXCLUDE_END);
$this->assertFalse($period->startExcluded());
$this->assertTrue($period->endExcluded());
}
/** @test */
public function exclude_all()
{
$period = Period::make('2018-01-01', '2018-01-31', null, Boundaries::EXCLUDE_ALL);
$this->assertTrue($period->startExcluded());
$this->assertTrue($period->endExcluded());
}
/** @test */
public function length_with_boundaries()
{
$period = Period::make('2018-01-01', '2018-01-31', null, Boundaries::EXCLUDE_START);
$this->assertEquals(30, $period->length());
$period = Period::make('2018-01-01', '2018-01-31', null, Boundaries::EXCLUDE_END);
$this->assertEquals(30, $period->length());
$period = Period::make('2018-01-01', '2018-01-31', null, Boundaries::EXCLUDE_ALL);
$this->assertEquals(29, $period->length());
}
/** @test */
public function overlap_with_excluded_boundaries()
{
$a = Period::make('2018-01-01', '2018-01-05', null, Boundaries::EXCLUDE_END);
$b = Period::make('2018-01-05', '2018-01-10');
$this->assertFalse($a->overlapsWith($b));
$a = Period::make('2018-01-01', '2018-01-05');
$b = Period::make('2018-01-05', '2018-01-10', null, Boundaries::EXCLUDE_START);
$this->assertFalse($a->overlapsWith($b));
$a = Period::make('2018-01-01', '2018-01-05');
$b = Period::make('2018-01-05', '2018-01-10');
$this->assertTrue($a->overlapsWith($b));
}
}