Passed
Branch master (73f5a3)
by Toni
02:45
created

WeekInYearTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 53
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A constructor_GivenInvalidWeek_ShouldThrowAnException() 0 3 1
A getInvalidDayDataProvider() 0 5 1
A includes_GivenDateWithMatchingWeek_ShouldReturnTrue() 0 8 1
A includes_GivenDateAtDifferentWeek_ShouldReturnFalse() 0 8 1
A constructor_GivenInvalidWeekInYearType_ShouldThrowTypeErrorException() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Adlogix\EventSchedulerTest\TemporalExpression;
6
7
use DateTime;
8
use PHPUnit\Framework\TestCase;
9
use Adlogix\EventScheduler\TemporalExpression\WeekInYear;
10
11
class WeekInYearTest extends TestCase
12
{
13
    /**
14
     * @test
15
     * @expectedException \TypeError
16
     */
17
    public function constructor_GivenInvalidWeekInYearType_ShouldThrowTypeErrorException()
18
    {
19
        new WeekInYear('invalid');
0 ignored issues
show
Bug introduced by
'invalid' of type string is incompatible with the type integer expected by parameter $week of Adlogix\EventScheduler\T...ekInYear::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

19
        new WeekInYear(/** @scrutinizer ignore-type */ 'invalid');
Loading history...
20
    }
21
22
    public function getInvalidDayDataProvider()
23
    {
24
        return [
25
            [0],
26
            [55],
27
        ];
28
    }
29
30
    /**
31
     * @test
32
     * @dataProvider getInvalidDayDataProvider
33
     * @expectedException \Exception
34
     */
35
    public function constructor_GivenInvalidWeek_ShouldThrowAnException($day)
36
    {
37
        new WeekInYear($day);
38
    }
39
40
    /**
41
     * @test
42
     */
43
    public function includes_GivenDateWithMatchingWeek_ShouldReturnTrue()
44
    {
45
        $date = new DateTime('2015-04-12');
46
        $expr = new WeekInYear(15);
47
48
        $isIncluded = $expr->includes($date);
49
50
        $this->assertThat($isIncluded, $this->isTrue());
51
    }
52
53
    /**
54
     * @test
55
     */
56
    public function includes_GivenDateAtDifferentWeek_ShouldReturnFalse()
57
    {
58
        $date = new DateTime('2015-01-01');
59
        $expr = new WeekInYear(15);
60
61
        $isIncluded = $expr->includes($date);
62
63
        $this->assertThat($isIncluded, $this->isFalse());
64
    }
65
}
66