Completed
Push — master ( 807d05...dfc103 )
by Chad
9s
created

KeyValidatorTraitTest::validateKeysWithString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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
 * @covers ::<private>
10
 */
11
final class KeyValidatorTraitTest extends \PHPUnit\Framework\TestCase
12
{
13
    use KeyValidatorTrait;
14
15
    /**
16
     * @test
17
     * @covers ::validateKey
18
     *
19
     * @return void
20
     */
21
    public function validateKeyWithString()
22
    {
23
        $this->assertNull($this->validateKey('a valid string'));
24
    }
25
26
    /**
27
     * @param mixed $key The key value which will throw an execption.
28
     *
29
     * @test
30
     * @covers ::validateKey
31
     * @expectedException \Psr\SimpleCache\InvalidArgumentException
32
     * @dataProvider provideInvalidKeys
33
     *
34
     * @return void
35
     */
36
    public function validateKeyWithInvalidValue($key)
37
    {
38
        $this->validateKey($key);
39
    }
40
41
    /**
42
     * @test
43
     * @covers ::validateKeys
44
     *
45
     * @return void
46
     */
47
    public function validateKeysWithString()
48
    {
49
        $this->assertNull($this->validateKeys(['a valid string', 'another valid string']));
50
    }
51
52
    /**
53
     * @param mixed $key The key value which will throw an execption.
54
     *
55
     * @test
56
     * @covers ::validateKeys
57
     * @expectedException \Psr\SimpleCache\InvalidArgumentException
58
     * @dataProvider provideInvalidKeys
59
     *
60
     * @return void
61
     */
62
    public function validateKeysWithInvalidValue($key)
63
    {
64
        $this->validateKeys(['valid_key', $key, 'another_valid_key']);
65
    }
66
67
    /**
68
     * Provides valid keys for testing.
69
     *
70
     * @return array
71
     */
72
    public function provideInvalidKeys() : array
73
    {
74
        return [
75
            ['an empty string' => ''],
76
            ['an object' => new \StdClass()],
77
            ['an integer' => 123],
78
            ['reserved characters' => '@key'],
79
        ];
80
    }
81
}
82