1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the core-bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) 2021 WEBEWEB |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace WBW\Bundle\CoreBundle\Tests\Form\DataTransformer; |
13
|
|
|
|
14
|
|
|
use DateTime; |
15
|
|
|
use DateTimeZone; |
16
|
|
|
use Throwable; |
17
|
|
|
use WBW\Bundle\CoreBundle\Tests\AbstractTestCase; |
18
|
|
|
use WBW\Bundle\CoreBundle\Tests\Fixtures\Form\DataTransformer\TestTimestampDataTransformer; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Abstract timestamp data transformer test. |
22
|
|
|
* |
23
|
|
|
* @author webeweb <https://github.com/webeweb> |
24
|
|
|
* @package WBW\Bundle\CoreBundle\Tests\Form\DataTransformer |
25
|
|
|
*/ |
26
|
|
|
class AbstractTimestampDataTransformerTest extends AbstractTestCase { |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Test reverseTransform() |
30
|
|
|
* |
31
|
|
|
* @return void |
32
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
33
|
|
|
*/ |
34
|
|
|
public function testReverseTransform(): void { |
35
|
|
|
|
36
|
|
|
// Set a date/time mock. |
37
|
|
|
$dateTime = new DateTime("2021-03-23 19:00:00", new DateTimeZone("UTC")); |
38
|
|
|
|
39
|
|
|
$obj = new TestTimestampDataTransformer("Y-m-d H:i:s", "UTC"); |
40
|
|
|
|
41
|
|
|
$fmt = $obj->getFormat(); |
42
|
|
|
$arg = $dateTime->format($fmt); |
43
|
|
|
|
44
|
|
|
$this->assertEquals(null, $obj->reverseTransform(null)); |
|
|
|
|
45
|
|
|
$this->assertEquals(null, $obj->reverseTransform("")); |
|
|
|
|
46
|
|
|
$this->assertEquals($dateTime->getTimestamp(), $obj->reverseTransform($arg)); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Test transform() |
51
|
|
|
* |
52
|
|
|
* @return void |
53
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
54
|
|
|
*/ |
55
|
|
|
public function testTransform(): void { |
56
|
|
|
|
57
|
|
|
// Set a date/time mock. |
58
|
|
|
$dateTime = new DateTime("2021-03-23 19:00:00", new DateTimeZone("UTC")); |
59
|
|
|
|
60
|
|
|
$obj = new TestTimestampDataTransformer("Y-m-d H:i:s", "UTC"); |
61
|
|
|
|
62
|
|
|
$fmt = $obj->getFormat(); |
63
|
|
|
$exp = $dateTime->format($fmt); |
64
|
|
|
|
65
|
|
|
$this->assertEquals(null, $obj->transform(null)); |
|
|
|
|
66
|
|
|
$this->assertEquals($exp, $obj->transform($dateTime->getTimestamp())); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.