TTLValidatorTraitTest::provideValidTTLs()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
namespace SubjectivePHPTest\Psr\SimpleCache;
4
5
use SubjectivePHP\Psr\SimpleCache\TTLValidatorTrait;
6
7
/**
8
 * @coversDefaultClass \SubjectivePHP\Psr\SimpleCache\TTLValidatorTrait
9
 */
10
final class TTLValidatorTraitTest extends \PHPUnit\Framework\TestCase
11
{
12
    use TTLValidatorTrait;
13
14
    /**
15
     * @param mixed $ttl The ttl value which will validate.
16
     *
17
     * @test
18
     * @covers ::validateTTL
19
     * @dataProvider provideValidTTLs
20
     *
21
     * @return void
22
     */
23
    public function validateTTLWithValidValues($ttl)
24
    {
25
        $this->assertNull($this->validateTTL($ttl));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->validateTTL($ttl) targeting SubjectivePHPTest\Psr\Si...raitTest::validateTTL() 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...
26
    }
27
28
    /**
29
     * Provides valid ttls for testing.
30
     *
31
     * @return array
32
     */
33
    public static function provideValidTTLs()
34
    {
35
        return [
36
            [null],
37
            [\DateInterval::createFromDateString('1 day')],
38
            [3600],
39
        ];
40
    }
41
42
    /**
43
     * @param mixed $ttl The ttl value which will throw an execption.
44
     *
45
     * @test
46
     * @covers ::validateTTL
47
     * @dataProvider provideInvalidTTLs
48
     *
49
     * @return void
50
     */
51
    public function validateTTLWithInvalidValue($ttl)
52
    {
53
        $this->expectException(\Psr\SimpleCache\InvalidArgumentException::class);
54
55
        $this->validateTTL($ttl);
56
    }
57
58
    /**
59
     * Provides valid ttls for testing.
60
     *
61
     * @return array
62
     */
63
    public static function provideInvalidTTLs()
64
    {
65
        return [
66
            [''],
67
            [1.1],
68
            [new \DateTime()],
69
        ];
70
    }
71
}
72