AbstractTimestampDataTransformerTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 14
dl 0
loc 41
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testReverseTransform() 0 13 1
A testTransform() 0 12 1
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));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $obj->reverseTransform(null) targeting WBW\Bundle\CoreBundle\Fo...mer::reverseTransform() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

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.

Loading history...
45
        $this->assertEquals(null, $obj->reverseTransform(""));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $obj->reverseTransform('') targeting WBW\Bundle\CoreBundle\Fo...mer::reverseTransform() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

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.

Loading history...
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));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $obj->transform(null) targeting WBW\Bundle\CoreBundle\Fo...ransformer::transform() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

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.

Loading history...
66
        $this->assertEquals($exp, $obj->transform($dateTime->getTimestamp()));
67
    }
68
}
69