|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace HMLB\Date\Tests\Interval; |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Date package. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Hugues Maignol <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
use HMLB\Date\Interval; |
|
15
|
|
|
use HMLB\Date\Tests\AbstractTestCase; |
|
16
|
|
|
use Symfony\Component\Translation\Loader\ArrayLoader; |
|
17
|
|
|
use Symfony\Component\Translation\Translator; |
|
18
|
|
|
|
|
19
|
|
|
class ForHumansTest extends AbstractTestCase |
|
20
|
|
|
{ |
|
21
|
|
|
public function testGetTranslator() |
|
22
|
|
|
{ |
|
23
|
|
|
$t = Interval::getTranslator(); |
|
24
|
|
|
$this->assertNotNull($t); |
|
25
|
|
|
$this->assertSame('en', $t->getLocale()); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
View Code Duplication |
public function testSetTranslator() |
|
|
|
|
|
|
29
|
|
|
{ |
|
30
|
|
|
$t = new Translator('fr'); |
|
31
|
|
|
$t->addLoader('array', new ArrayLoader()); |
|
32
|
|
|
Interval::setTranslator($t); |
|
33
|
|
|
|
|
34
|
|
|
$t = Interval::getTranslator(); |
|
35
|
|
|
$this->assertNotNull($t); |
|
36
|
|
|
$this->assertSame('fr', $t->getLocale()); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testGetLocale() |
|
40
|
|
|
{ |
|
41
|
|
|
Interval::setLocale('en'); |
|
42
|
|
|
$this->assertSame('en', Interval::getLocale()); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testSetLocale() |
|
46
|
|
|
{ |
|
47
|
|
|
Interval::setLocale('en'); |
|
48
|
|
|
$this->assertSame('en', Interval::getLocale()); |
|
49
|
|
|
Interval::setLocale('fr'); |
|
50
|
|
|
$this->assertSame('fr', Interval::getLocale()); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function testYear() |
|
54
|
|
|
{ |
|
55
|
|
|
Interval::setLocale('en'); |
|
56
|
|
|
$this->assertSame('1 year', Interval::year()->forHumans()); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function testYearToString() |
|
60
|
|
|
{ |
|
61
|
|
|
Interval::setLocale('en'); |
|
62
|
|
|
$this->assertSame('1 year:abc', Interval::year().':abc'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testYears() |
|
66
|
|
|
{ |
|
67
|
|
|
Interval::setLocale('en'); |
|
68
|
|
|
$this->assertSame('2 years', Interval::years(2)->forHumans()); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function testYearsAndMonth() |
|
72
|
|
|
{ |
|
73
|
|
|
Interval::setLocale('en'); |
|
74
|
|
|
$this->assertSame('2 years 1 month', Interval::create(2, 1)->forHumans()); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function testAll() |
|
78
|
|
|
{ |
|
79
|
|
|
Interval::setLocale('en'); |
|
80
|
|
|
$ci = Interval::create(11, 1, 2, 5, 22, 33, 55)->forHumans(); |
|
81
|
|
|
$this->assertSame('11 years 1 month 2 weeks 5 days 22 hours 33 minutes 55 seconds', $ci); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function testYearsAndMonthInFrench() |
|
85
|
|
|
{ |
|
86
|
|
|
Interval::setLocale('fr'); |
|
87
|
|
|
$this->assertSame('2 ans 1 mois', Interval::create(2, 1)->forHumans()); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function testYearsAndMonthInGerman() |
|
91
|
|
|
{ |
|
92
|
|
|
Interval::setLocale('de'); |
|
93
|
|
|
$this->assertSame('1 Jahr 1 Monat', Interval::create(1, 1)->forHumans()); |
|
94
|
|
|
$this->assertSame('2 Jahre 1 Monat', Interval::create(2, 1)->forHumans()); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function testYearsAndMonthInBulgarian() |
|
98
|
|
|
{ |
|
99
|
|
|
Interval::setLocale('bg'); |
|
100
|
|
|
$this->assertSame('1 година 1 месец', Interval::create(1, 1)->forHumans()); |
|
101
|
|
|
$this->assertSame('2 години 1 месец', Interval::create(2, 1)->forHumans()); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function testYearsAndMonthInCatalan() |
|
105
|
|
|
{ |
|
106
|
|
|
Interval::setLocale('ca'); |
|
107
|
|
|
$this->assertSame('1 any 1 mes', Interval::create(1, 1)->forHumans()); |
|
108
|
|
|
$this->assertSame('2 anys 1 mes', Interval::create(2, 1)->forHumans()); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function testYearsAndMonthInCzech() |
|
112
|
|
|
{ |
|
113
|
|
|
Interval::setLocale('cs'); |
|
114
|
|
|
$this->assertSame('1 rok 1 měsíc', Interval::create(1, 1)->forHumans()); |
|
115
|
|
|
$this->assertSame('2 roky 1 měsíc', Interval::create(2, 1)->forHumans()); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
public function testYearsAndMonthInGreek() |
|
119
|
|
|
{ |
|
120
|
|
|
Interval::setLocale('el'); |
|
121
|
|
|
$this->assertSame('1 χρόνος 1 μήνας', Interval::create(1, 1)->forHumans()); |
|
122
|
|
|
$this->assertSame('2 χρόνια 1 μήνας', Interval::create(2, 1)->forHumans()); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
public function testYearsAndMonthsInDanish() |
|
126
|
|
|
{ |
|
127
|
|
|
Interval::setLocale('da'); |
|
128
|
|
|
$this->assertSame('1 år 1 måned', Interval::create(1, 1)->forHumans()); |
|
129
|
|
|
$this->assertSame('2 år 1 måned', Interval::create(2, 1)->forHumans()); |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.