Passed
Push — related_object ( 750d5e...9b2cd9 )
by Donald
01:33
created

ParseTest::mismatchedKeyAndIndexDataProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php namespace Chekote\NounStore\Key;
2
3
use Chekote\Phake\Phake;
4
use InvalidArgumentException;
5
6
/**
7
 * @covers \Chekote\NounStore\Key::parse()
8
 */
9
class ParseTest extends KeyTest
10
{
11
    public function setUp()
12
    {
13
        parent::setUp();
14
15
        /* @noinspection PhpUndefinedMethodInspection */
16
        Phake::when($this->key)->parse(Phake::anyParameters())->thenCallParent();
17
    }
18
19
    /**
20
     * Provides examples of valid key and index pairs with expected parse results.
21
     *
22
     * @return array
23
     */
24
    public function successScenarioDataProvider()
25
    {
26
        return [
27
        //   key           index   parsedKey,  parsedIndex
28
            ['Thing',       null, 'Thing',            null], // no nth in key or index param
29
            ['1st Thing',   null, 'Thing',               0], // 1st in key with no index param
30
            ['1st Thing',      0, 'Thing',               0], // nth in key with matching index param
31
            ['2nd Thing',   null, 'Thing',               1], // 2nd in key with no index param
32
            ['3rd Thing',   null, 'Thing',               2], // 3rd in key with no index param
33
            ['4th Thing',   null, 'Thing',               3], // 3th in key with no index param
34
            ['478th Thing', null, 'Thing',             477], // high nth in key with no index param
35
            ['Thing',          0, 'Thing',               0], // no nth in key with 0 index param
36
            ['Thing',         49, 'Thing',              49], // no nth in key with high index param
37
        ];
38
    }
39
40
    /**
41
     * Tests that calling Key::parse with valid key and index combinations works correctly.
42
     *
43
     * @dataProvider successScenarioDataProvider
44
     * @param string $key         the key to parse
45
     * @param int    $index       the index to pass along with the key
46
     * @param string $parsedKey   the expected resulting parsed key
47
     * @param int    $parsedIndex the expected resulting parsed index
48
     */
49
    public function testSuccessScenario($key, $index, $parsedKey, $parsedIndex)
50
    {
51
        $this->assertEquals([$parsedKey, $parsedIndex], $this->key->parse($key, $index));
0 ignored issues
show
Bug introduced by
The method parse() does not exist on Phake_IMock. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

51
        $this->assertEquals([$parsedKey, $parsedIndex], $this->key->/** @scrutinizer ignore-call */ parse($key, $index));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
52
    }
53
54
    /**
55
     * Provides examples of mismatched key & index pairs.
56
     *
57
     * @return array
58
     */
59
    public function mismatchedKeyAndIndexDataProvider()
60
    {
61
        return [
62
            ['1st Thing', 1],
63
            ['1st Thing', 2],
64
            ['4th Person', 0],
65
            ['4th Person', 4],
66
            ['4th Person', 10],
67
        ];
68
    }
69
70
    /**
71
     * Tests that calling Key::parse with mismatched key and index param throws an exception.
72
     *
73
     * @dataProvider mismatchedKeyAndIndexDataProvider
74
     * @param string $key   the key to parse
75
     * @param string $index the mismatched index to pass along with the key
76
     */
77
    public function testParseKeyThrowsExceptionIfKeyAndIndexMismatch($key, $index)
78
    {
79
        $this->expectException(InvalidArgumentException::class);
80
        $this->expectExceptionMessage(
81
            "$index was provided for index param when key '$key' contains an nth value, but they do not match"
82
        );
83
84
        $this->key->parse($key, $index);
85
    }
86
}
87