Passed
Pull Request — 2.0 (#36)
by Donald
02:59 queued 01:27
created

ParseTest::invalidKeyDataProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
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();
0 ignored issues
show
Bug introduced by
It seems like $this->key can also be of type Chekote\NounStore\Key; however, parameter $mock of Phake::when() does only seem to accept Phake_IMock, maybe add an additional type check? ( Ignorable by Annotation )

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

16
        Phake::when(/** @scrutinizer ignore-type */ $this->key)->parse(Phake::anyParameters())->thenCallParent();
Loading history...
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             parsedKey, parsedIndex
28
            ['Thing',       'Thing',           null],
29
            ['1st Thing',   'Thing',              0],
30
            ['2nd Thing',   'Thing',              1],
31
            ['3rd Thing',   'Thing',              2],
32
            ['4th Thing',   'Thing',              3],
33
            ['478th Thing', 'Thing',            477],
34
        ];
35
    }
36
37
    /**
38
     * Tests that calling Key::parse with valid key works correctly.
39
     *
40
     * @dataProvider successScenarioDataProvider
41
     * @param string $key         the key to parse
42
     * @param string $parsedKey   the expected resulting parsed key
43
     * @param int    $parsedIndex the expected resulting parsed index
44
     */
45
    public function testSuccessScenario($key, $parsedKey, $parsedIndex)
46
    {
47
        $this->assertEquals([$parsedKey, $parsedIndex], $this->key->parse($key));
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

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

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...
48
    }
49
50
    /**
51
     * Provides examples of invalid keys.
52
     *
53
     * @return array
54
     */
55
    public function invalidKeyDataProvider()
56
    {
57
        return [
58
            ["Thing's stuff"],
59
            ["1st Thing's thingamajig"],
60
        ];
61
    }
62
63
    /**
64
     * Tests that calling Key::parse with an invalid key throws an exception.
65
     *
66
     * @dataProvider invalidKeyDataProvider
67
     * @param string $key the key to parse
68
     */
69
    public function testParseKeyThrowsExceptionIfKeyAndIndexMismatch($key)
70
    {
71
        $this->expectException(InvalidArgumentException::class);
72
        $this->expectExceptionMessage('Key syntax is invalid');
73
74
        $this->key->parse($key);
75
    }
76
}
77