generated from ergebnis/php-cs-fixer-config-template
/
YearsTest.php
92 lines (74 loc) 路 2.3 KB
/
YearsTest.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
<?php
declare(strict_types=1);
/**
* Copyright (c) 2019-2020 Andreas M枚ller
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* @see https://github.com/ergebnis/php-cs-fixer-config
*/
namespace Ergebnis\PhpCsFixer\Config\Test\Unit\License\Copyright;
use Ergebnis\PhpCsFixer\Config\License\Copyright\Year;
use Ergebnis\PhpCsFixer\Config\License\Copyright\Years;
use Ergebnis\Test\Util\Helper;
use PHPUnit\Framework;
/**
* @internal
*
* @covers \Ergebnis\PhpCsFixer\Config\License\Copyright\Years
*
* @uses \Ergebnis\PhpCsFixer\Config\License\Copyright\Holder
* @uses \Ergebnis\PhpCsFixer\Config\License\Copyright\Year
* @uses \Ergebnis\PhpCsFixer\Config\License\Url
*/
final class YearsTest extends Framework\TestCase
{
use Helper;
public function testFromRangeRequiresStartYearToBeEqualOrLessThanEndYear(): void
{
$start = Year::fromString('2020');
$end = Year::fromString('2019');
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage(\sprintf(
'Start year "%s" needs to be equal to or less than end year "%s".',
$start->toString(),
$end->toString()
));
Years::fromRange(
$start,
$end
);
}
public function testFromRangeReturnsYearsWhenStartYearEqualsEndYear(): void
{
$start = Year::fromString('2020');
$end = Year::fromString('2020');
$years = Years::fromRange(
$start,
$end
);
self::assertSame($start->toString(), $years->toString());
}
public function testFromRangeReturnsYearsWhenStartYearIsLessThanEndYear(): void
{
$start = Year::fromString('2019');
$end = Year::fromString('2020');
$years = Years::fromRange(
$start,
$end
);
$expected = \sprintf(
'%s-%s',
$start->toString(),
$end->toString()
);
self::assertSame($expected, $years->toString());
}
public function testFromYearReturnsYears(): void
{
$year = Year::fromString('2019');
$years = Years::fromYear($year);
self::assertSame($year->toString(), $years->toString());
}
}