Failed Conditions
Push — master ( fb9d58...06aef8 )
by Donald
01:41
created

ParseTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 42
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testHappyPath() 0 14 1
A testInvalidArgumentExceptionBubblesUpFromParseNoun() 0 16 1
A setUp() 0 6 1
1
<?php namespace Unit\Chekote\NounStore\Key;
2
3
use InvalidArgumentException;
4
use Unit\Chekote\Phake\Phake;
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
    public function testHappyPath()
20
    {
21
        $key = "2nd Customer's 4th Car";
22
        $splitNouns = ['2nd Customer', '4th Car'];
23
        $parsedKey = [['Customer', 1], ['Car', 3]];
24
25
        /* @noinspection PhpUndefinedMethodInspection */
26
        {
27
            Phake::expect($this->key, 1)->splitPossessions($key)->thenReturn($splitNouns);
0 ignored issues
show
Bug introduced by
The method splitPossessions() does not exist on Unit\Chekote\Phake\Expectation. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

27
            Phake::expect($this->key, 1)->/** @scrutinizer ignore-call */ splitPossessions($key)->thenReturn($splitNouns);
Loading history...
28
            Phake::expect($this->key, 1)->parseNoun($splitNouns[0])->thenReturn($parsedKey[0]);
0 ignored issues
show
Bug introduced by
The method parseNoun() does not exist on Unit\Chekote\Phake\Expectation. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

28
            Phake::expect($this->key, 1)->/** @scrutinizer ignore-call */ parseNoun($splitNouns[0])->thenReturn($parsedKey[0]);
Loading history...
29
            Phake::expect($this->key, 1)->parseNoun($splitNouns[1])->thenReturn($parsedKey[1]);
30
        }
31
32
        $this->assertEquals($parsedKey, $this->key->parse($key));
0 ignored issues
show
Bug introduced by
The method parse() does not exist on Unit\Chekote\NounStore\Assert\KeyPhake. ( Ignorable by Annotation )

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

32
        $this->assertEquals($parsedKey, $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...
33
    }
34
35
    public function testInvalidArgumentExceptionBubblesUpFromParseNoun()
36
    {
37
        $invalidKey = "Customer's's Car";
38
        $splitNouns = ["Customer's", 'Car'];
39
        $exception = new InvalidArgumentException('Key syntax is invalid');
40
41
        /* @noinspection PhpUndefinedMethodInspection */
42
        {
43
            Phake::expect($this->key, 1)->splitPossessions($invalidKey)->thenReturn($splitNouns);
44
            Phake::expect($this->key, 1)->parseNoun($splitNouns[0])->thenThrow($exception);
45
        }
46
47
        $this->expectException(get_class($exception));
48
        $this->expectExceptionMessage($exception->getMessage());
49
50
        $this->key->parse($invalidKey);
51
    }
52
}
53