Passed
Push — master ( 639b92...a2ec98 )
by Donald
13:52
created

BuildKeyTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 36
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testBuildKeyBuildsValidKeyAndIndexCombinations() 0 8 1
A validKeyAndIndexCombinationsDataProvider() 0 11 1
1
<?php namespace Chekote\NounStore\Store;
2
3
use Chekote\NounStore\Store;
4
use ReflectionClass;
5
6
/**
7
 * @covers Store::buildKey()
8
 */
9
class BuildKeyTest extends StoreTest
10
{
11
    /**
12
     * Tests that calling Store::buildKey with valid key and index combinations works correctly.
13
     *
14
     * @dataProvider validKeyAndIndexCombinationsDataProvider
15
     * @param string $key      the key to use for the build
16
     * @param int    $index    the index to use for the build
17
     * @param string $expected the expected resulting key
18
     */
19
    public function testBuildKeyBuildsValidKeyAndIndexCombinations($key, $index, $expected)
20
    {
21
        $buildKey = (new ReflectionClass(Store::class))->getMethod('buildKey');
22
        $buildKey->setAccessible(true);
23
24
        $actual = $buildKey->invoke($this->store, $key, $index);
25
26
        $this->assertEquals($expected, $actual);
27
    }
28
29
    /**
30
     * Provides examples of valid key and index pairs with expected build results.
31
     *
32
     * @return array
33
     */
34
    public function validKeyAndIndexCombinationsDataProvider()
35
    {
36
        return [
37
            // key   index  expected result
38
            ['Thing', null, 'Thing'],
39
            ['Thing',    0, '1st Thing'],
40
            ['Thing',    1, '2nd Thing'],
41
            ['Thing',    2, '3rd Thing'],
42
            ['Thing',    3, '4th Thing'],
43
            ['Thing',    4, '5th Thing'],
44
            ['Thing',  477, '478th Thing'],
45
        ];
46
    }
47
}
48