HelpersTest::testTimestamp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Spiral\Tests\Snapshotter;
4
5
use Spiral\Snapshotter\FileHandler\Entities\FileTimestamp;
6
use Spiral\Snapshotter\Helpers\Names;
7
use Spiral\Snapshotter\Helpers\Timestamps;
8
use Spiral\Tests\BaseTest;
9
10
class HelpersTest extends BaseTest
11
{
12
    public function testName()
13
    {
14
        /** @var Names $names */
15
        $names = $this->container->get(Names::class);
16
17
        $this->assertEquals('filename', $names->onlyName('filename'));
18
        $this->assertEquals('filename', $names->onlyName('filename/'));
19
        $this->assertEquals('filename', $names->onlyName('some/path/to/filename'));
20
        $this->assertEquals('filename', $names->onlyName('/some/path/to/filename/'));
21
        $this->assertEquals('filename', $names->onlyName('C:\some/path/to/filename'));
22
        $this->assertEquals('filename', $names->onlyName('some\path/to\filename'));
23
    }
24
25
    public function testTimestamp()
26
    {
27
        /** @var Timestamps $names */
28
        $names = $this->container->get(Timestamps::class);
29
30
        $timestamp = new FileTimestamp(new \DateTime(), []);
0 ignored issues
show
Documentation introduced by
new \DateTime() is of type object<DateTime>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
31
32
        $this->assertEquals($timestamp, $names->getTime($timestamp));
33
        $this->assertNotEquals('filename', $names->getTime($timestamp, true));
34
    }
35
}