Failed Conditions
Push — possessive_nouns ( b5335d...fee3e3 )
by Donald
01:41
created

testInvalidArgumentExceptionBubblesUpFromParseNoun()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 15
rs 10
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
    public function testHappyPath() {
20
        $key = "2nd Customer's 4th Car";
21
        $splitNouns = ['2nd Customer', '4th Car'];
22
        $parsedKey = [['Customer', 1], ['Car', 3]];
23
24
        /* @noinspection PhpUndefinedMethodInspection */
25
        {
26
            Phake::expect($this->key, 1)->splitPossessions($key)->thenReturn($splitNouns);
0 ignored issues
show
Bug introduced by
It seems like $this->key can also be of type Chekote\NounStore\Key; however, parameter $mock of Chekote\Phake\Phake::expect() 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

26
            Phake::expect(/** @scrutinizer ignore-type */ $this->key, 1)->splitPossessions($key)->thenReturn($splitNouns);
Loading history...
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

26
            Phake::expect($this->key, 1)->/** @scrutinizer ignore-call */ splitPossessions($key)->thenReturn($splitNouns);
Loading history...
27
            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 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 */ parseNoun($splitNouns[0])->thenReturn($parsedKey[0]);
Loading history...
28
            Phake::expect($this->key, 1)->parseNoun($splitNouns[1])->thenReturn($parsedKey[1]);
29
        }
30
31
        $this->assertEquals($parsedKey, $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

31
        $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...
32
    }
33
34
    public function testInvalidArgumentExceptionBubblesUpFromParseNoun() {
35
        $invalidKey = "Customer's's Car";
36
        $splitNouns = ["Customer's", 'Car'];
37
        $exception = new InvalidArgumentException('Key syntax is invalid');
38
39
        /* @noinspection PhpUndefinedMethodInspection */
40
        {
41
            Phake::expect($this->key, 1)->splitPossessions($invalidKey)->thenReturn($splitNouns);
0 ignored issues
show
Bug introduced by
It seems like $this->key can also be of type Chekote\NounStore\Key; however, parameter $mock of Chekote\Phake\Phake::expect() 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

41
            Phake::expect(/** @scrutinizer ignore-type */ $this->key, 1)->splitPossessions($invalidKey)->thenReturn($splitNouns);
Loading history...
42
            Phake::expect($this->key, 1)->parseNoun($splitNouns[0])->thenThrow($exception);
43
        }
44
45
        $this->expectException(get_class($exception));
46
        $this->expectExceptionMessage($exception->getMessage());
47
48
        $this->key->parse($invalidKey);
49
    }
50
}
51