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
|
|||
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
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 The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||
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 |
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.