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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
<?php
/*
* This file is part of the Carbon package.
*
* (c) Brian Nesbitt <brian@nesbot.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Tests;
use Carbon\Carbon;
use Carbon\CarbonInterval;
use Closure;
use PHPUnit_Framework_TestCase;
abstract class AbstractTestCase extends PHPUnit_Framework_TestCase
{
/**
* @var \Carbon\Carbon
*/
protected $now;
/**
* @var string
*/
private $saveTz;
protected function setUp()
{
//save current timezone
$this->saveTz = date_default_timezone_get();
date_default_timezone_set('America/Toronto');
Carbon::setTestNow($this->now = Carbon::now());
}
protected function tearDown()
{
date_default_timezone_set($this->saveTz);
Carbon::setTestNow();
Carbon::resetMonthsOverflow();
}
protected function assertCarbon(Carbon $d, $year, $month, $day, $hour = null, $minute = null, $second = null)
{
$actual = array(
'years' => $year,
'months' => $month,
'day' => $day,
);
$expected = array(
'years' => $d->year,
'months' => $d->month,
'day' => $d->day,
);
if ($hour !== null) {
$expected['hours'] = $d->hour;
$actual['hours'] = $hour;
}
if ($minute !== null) {
$expected['minutes'] = $d->minute;
$actual['minutes'] = $minute;
}
if ($second !== null) {
$expected['seconds'] = $d->second;
$actual['seconds'] = $second;
}
$this->assertSame($expected, $actual);
}
protected function assertInstanceOfCarbon($d)
{
$this->assertInstanceOf('Carbon\Carbon', $d);
}
protected function assertCarbonInterval(CarbonInterval $ci, $years, $months = null, $days = null, $hours = null, $minutes = null, $seconds = null)
{
$expected = array('years' => $ci->years);
$actual = array('years' => $years);
if ($months !== null) {
$expected['months'] = $ci->months;
$actual['months'] = $months;
}
if ($days !== null) {
$expected['days'] = $ci->dayz;
$actual['days'] = $days;
}
if ($hours !== null) {
$expected['hours'] = $ci->hours;
$actual['hours'] = $hours;
}
if ($minutes !== null) {
$expected['minutes'] = $ci->minutes;
$actual['minutes'] = $minutes;
}
if ($seconds !== null) {
$expected['seconds'] = $ci->seconds;
$actual['seconds'] = $seconds;
}
$this->assertSame($expected, $actual);
}
protected function assertInstanceOfCarbonInterval($d)
{
$this->assertInstanceOf('Carbon\CarbonInterval', $d);
}
protected function wrapWithTestNow(Closure $func, Carbon $dt = null)
{
Carbon::setTestNow($dt ?: Carbon::now());
$func();
Carbon::setTestNow();
}
protected function wrapWithNonDstDate(Closure $func)
{
$this->wrapWithTestNow($func, Carbon::now()->startOfYear());
}
}
|