|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Validator |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (c) 2017 pudelek.org.pl |
|
6
|
|
|
* |
|
7
|
|
|
* @license MIT License (MIT) |
|
8
|
|
|
* |
|
9
|
|
|
* For the full copyright and license information, please view source file |
|
10
|
|
|
* that is bundled with this package in the file LICENSE |
|
11
|
|
|
* |
|
12
|
|
|
* @author Marcin Pudełek <[email protected]> |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace mrcnpdlk\Validator; |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
use mrcnpdlk\Validator\Types\DateTime; |
|
19
|
|
|
|
|
20
|
|
|
class DateTimeTest extends TestCase |
|
21
|
|
|
{ |
|
22
|
|
|
public function testPnaValidShort() |
|
23
|
|
|
{ |
|
24
|
|
|
$this->assertTrue(DateTime::isValid('2017-10-01', false)); |
|
25
|
|
|
$res = new DateTime('2017-10-01'); |
|
26
|
|
|
$this->assertEquals('2017-10-01 00:00:00', $res->get()); |
|
27
|
|
|
|
|
28
|
|
|
$res = new DateTime('2017-10-01 22:15:45'); |
|
29
|
|
|
$this->assertEquals('2017-10-01 22:15:45', $res->get()); |
|
30
|
|
|
$this->assertEquals('2017', $res->getYear()); |
|
31
|
|
|
$this->assertEquals('10', $res->getMonth()); |
|
32
|
|
|
$this->assertEquals('01', $res->getDay()); |
|
33
|
|
|
$this->assertEquals('22:15:45', $res->getTime()); |
|
34
|
|
|
$this->assertEquals('22', $res->getHour()); |
|
35
|
|
|
$this->assertEquals('15', $res->getMinute()); |
|
36
|
|
|
$this->assertEquals('45', $res->getSecond()); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @expectedException \mrcnpdlk\Validator\Exception |
|
41
|
|
|
*/ |
|
42
|
|
|
public function testDateInvalid() |
|
43
|
|
|
{ |
|
44
|
|
|
DateTime::isValid('2017-10-01 00:01:78', true); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @expectedException \mrcnpdlk\Validator\Exception |
|
49
|
|
|
*/ |
|
50
|
|
|
public function testDateInvalidInt() |
|
51
|
|
|
{ |
|
52
|
|
|
DateTime::isValid(1, true); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|