Skip to content

Commit 8736017

Browse files
committed
DateTime test improved
1 parent 6cca07d commit 8736017

File tree

2 files changed

+72
-2
lines changed

2 files changed

+72
-2
lines changed

src/AbraFlexi/DateTime.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ class DateTime extends \DateTime {
2121
* @var bool
2222
*/
2323
public bool $isNull = false;
24+
25+
/**
26+
* Default output format
27+
* @var string
28+
*/
29+
public static $format = 'Y-m-d\TH:i:s.u+P';
2430

2531
/**
2632
* AbraFlexi dateTime to PHP DateTime conversion
@@ -33,7 +39,7 @@ public function __construct(string $flexidatetime = 'NOW') {
3339
$this->isNull = empty($flexidatetime);
3440
$format = '';
3541
if (strchr($flexidatetime, '.')) { //NewFormat
36-
$format = RO::$DateTimeFormat;
42+
$format = self::$format;
3743
} elseif (!empty($flexidatetime) && ($flexidatetime != 'NOW')) { // Old format
3844
$format = 'Y-m-d\TH:i:s+P';
3945
}
@@ -46,7 +52,7 @@ public function __construct(string $flexidatetime = 'NOW') {
4652
* @return string
4753
*/
4854
public function __toString() {
49-
return $this->isNull ? '' : $this->format(RO::$DateTimeFormat);
55+
return $this->isNull ? '' : $this->format(self::$format);
5056
}
5157

5258
}

testing/AbraFlexi/DateTimeTest.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
namespace Test\AbraFlexi;
4+
5+
use AbraFlexi\DateTime;
6+
7+
/**
8+
* Generated by PHPUnit_SkeletonGenerator on 2021-10-19 at 15:21:39.
9+
*/
10+
class DateTimeTest extends \PHPUnit\Framework\TestCase {
11+
12+
/**
13+
* @var DateTime
14+
*/
15+
protected $object;
16+
17+
/**
18+
* Sets up the fixture, for example, opens a network connection.
19+
* This method is called before a test is executed.
20+
*/
21+
protected function setUp(): void {
22+
$this->object = new DateTime();
23+
}
24+
25+
/**
26+
* Tears down the fixture, for example, closes a network connection.
27+
* This method is called after a test is executed.
28+
*/
29+
protected function tearDown(): void {
30+
31+
}
32+
33+
/**
34+
* Test Constructor
35+
*
36+
* @covers AbraFlexi\DateTime::__construct
37+
*/
38+
public function testConstructor() {
39+
$classname = get_class($this->object);
40+
41+
// Get mock, without the constructor being called
42+
$mock = $this->getMockBuilder($classname)
43+
->disableOriginalConstructor()
44+
->getMockForAbstractClass();
45+
46+
$mock->__construct('');
47+
$this->assertTrue($mock->isNull);
48+
49+
$mock->__construct('NOW');
50+
$this->assertFalse($mock->isNull);
51+
$mock->__construct('2021-11-09T12:03:53++00:00');
52+
53+
$mock->__construct('2021-10-19T15:12:53.435+02:00');
54+
}
55+
56+
/**
57+
* @covers AbraFlexi\DateTime::__toString
58+
*/
59+
public function test__toString() {
60+
$this->object->setDate(2323, 2, 3)->setTime(2, 3, 2, 3);
61+
$this->assertEquals('2323-02-03T02:03:02.000003++00:00', $this->object->__toString());
62+
}
63+
64+
}

0 commit comments

Comments
 (0)