forked from CarbonPHP/carbon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLastErrorTest.php
More file actions
82 lines (67 loc) · 1.93 KB
/
LastErrorTest.php
File metadata and controls
82 lines (67 loc) · 1.93 KB
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
<?php
declare(strict_types=1);
/**
* 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\Carbon;
use Carbon\Carbon;
use Carbon\Traits\Creator;
use DateTime;
use Tests\AbstractTestCase;
class LastErrorTest extends AbstractTestCase
{
/**
* @var array
*/
protected $lastErrors;
/**
* @var array
*/
protected $noErrors;
protected function setUp(): void
{
parent::setUp();
$this->lastErrors = [
'warning_count' => 1,
'warnings' => ['11' => 'The parsed date was invalid'],
'error_count' => 0,
'errors' => [],
];
}
public function testCreateHandlesLastErrors()
{
$carbon = new Carbon('2017-02-30');
$datetime = new DateTime('2017-02-30');
$this->assertSame($this->lastErrors, $carbon->getLastErrors());
$this->assertSame($carbon->getLastErrors(), $datetime->getLastErrors());
$carbon = new Carbon('2017-02-15');
$this->assertFalse($carbon->getLastErrors());
}
public function testLastErrorsInitialization()
{
$obj = new class() {
use Creator;
/** @phpstan-ignore-next-line */
public function __construct($time = null, $tz = null)
{
}
public function triggerError()
{
self::setLastErrors([
'warning_count' => 1,
'warnings' => ['11' => 'The parsed date was invalid'],
'error_count' => 0,
'errors' => [],
]);
}
};
$this->assertFalse($obj::getLastErrors());
$obj->triggerError();
$this->assertSame($this->lastErrors, $obj::getLastErrors());
}
}