Failed Conditions
Push — complex_graph ( 39e222...60f2a1 )
by Donald
01:38
created

ParseTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testInvalidArgumentExceptionBubblesUpFromParseNoun() 0 16 1
A testHappyPath() 0 15 1
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
    public function testHappyPath()
20
    {
21
        $key = "2nd Customer's 4th Car";
22
        $splitNouns = ['2nd Customer', '4th Car'];
23
        $parsedNouns = ['Customer.1', 'Car.3'];
24
        $parsedKey = 'Customer.1.Car.3';
25
26
        /* @noinspection PhpUndefinedMethodInspection */
27
        {
28
            Phake::expect($this->key, 1)->splitPossessions($key)->thenReturn($splitNouns);
0 ignored issues
show
Bug introduced by
The method splitPossessions() does not exist on 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 */ splitPossessions($key)->thenReturn($splitNouns);
Loading history...
29
            Phake::expect($this->key, 1)->parseNoun($splitNouns[0])->thenReturn($parsedNouns[0]);
0 ignored issues
show
Bug introduced by
The method parseNoun() does not exist on 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

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

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

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