validateKeyWithInvalidValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SubjectivePHPTest\Psr\SimpleCache;
4
5
use SubjectivePHP\Psr\SimpleCache\KeyValidatorTrait;
6
7
/**
8
 * @coversDefaultClass \SubjectivePHP\Psr\SimpleCache\KeyValidatorTrait
9
 */
10
final class KeyValidatorTraitTest extends \PHPUnit\Framework\TestCase
11
{
12
    use KeyValidatorTrait;
13
14
    /**
15
     * @test
16
     * @covers ::validateKey
17
     *
18
     * @return void
19
     */
20
    public function validateKeyWithString()
21
    {
22
        $this->assertNull($this->validateKey('a valid string'));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->validateKey('a valid string') targeting SubjectivePHPTest\Psr\Si...raitTest::validateKey() 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...
23
    }
24
25
    /**
26
     * @param mixed $key The key value which will throw an execption.
27
     *
28
     * @test
29
     * @covers ::validateKey
30
     * @dataProvider provideInvalidKeys
31
     *
32
     * @return void
33
     */
34
    public function validateKeyWithInvalidValue($key)
35
    {
36
        $this->expectException(\Psr\SimpleCache\InvalidArgumentException::class);
37
        $this->validateKey($key);
38
    }
39
40
    /**
41
     * @test
42
     * @covers ::validateKeys
43
     *
44
     * @return void
45
     */
46
    public function validateKeysWithString()
47
    {
48
        $this->assertNull($this->validateKeys(['a valid string', 'another valid string']));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->validateKeys(arra...another valid string')) targeting SubjectivePHPTest\Psr\Si...aitTest::validateKeys() 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...
49
    }
50
51
    /**
52
     * @param mixed $key The key value which will throw an execption.
53
     *
54
     * @test
55
     * @covers ::validateKeys
56
     * @dataProvider provideInvalidKeys
57
     *
58
     * @return void
59
     */
60
    public function validateKeysWithInvalidValue($key)
61
    {
62
        $this->expectException(\Psr\SimpleCache\InvalidArgumentException::class);
63
        $this->validateKeys(['valid_key', $key, 'another_valid_key']);
64
    }
65
66
    /**
67
     * Provides valid keys for testing.
68
     *
69
     * @return array
70
     */
71
    public static function provideInvalidKeys() : array
72
    {
73
        return [
74
            [''],
75
            [new \StdClass()],
76
            [123],
77
            ['@key'],
78
        ];
79
    }
80
}
81