Passed
Pull Request — 2.0 (#28)
by Donald
03:05 queued 01:30
created

testInvalidKeyThrowsInvalidArgumentException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php namespace Chekote\NounStore\Key;
2
3
use Chekote\NounStore\Key;
4
use Chekote\Phake\Phake;
5
use InvalidArgumentException;
6
7
/**
8
 * @covers \Chekote\NounStore\Key::parse()
9
 */
10
class ParseTest extends KeyTest
11
{
12
    public function setUp()
13
    {
14
        parent::setUp();
15
16
        /* @noinspection PhpUndefinedMethodInspection */
17
        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

17
        Phake::when(/** @scrutinizer ignore-type */ $this->key)->parse(Phake::anyParameters())->thenCallParent();
Loading history...
18
    }
19
20
    public function testInvalidKeyThrowsInvalidArgumentException()
21
    {
22
        $this->expectException(InvalidArgumentException::class);
23
        $this->expectExceptionMessage('Key is not valid. Must match pattern ' . Key::REGEX_KEY);
24
25
        $this->key->parse("'''''");
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

25
        $this->key->/** @scrutinizer ignore-call */ 
26
                    parse("'''''");

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...
26
    }
27
28
    public function testValidKeyIsProcessed()
29
    {
30
        $key = "10th thing's address";
31
        $index = null;
32
33
        $pregResult = ["10th thing's address", '10th ', '10', 'thing', "'s address", 'address'];
34
        $processResult = ['thing', 9, 'address'];
35
36
        /* @noinspection PhpUndefinedMethodInspection */
37
        Phake::expect($this->key, 1)->processMatches($index, $pregResult)->thenReturn($processResult);
0 ignored issues
show
Bug introduced by
The method processMatches() 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

37
        Phake::expect($this->key, 1)->/** @scrutinizer ignore-call */ processMatches($index, $pregResult)->thenReturn($processResult);
Loading history...
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

37
        Phake::expect(/** @scrutinizer ignore-type */ $this->key, 1)->processMatches($index, $pregResult)->thenReturn($processResult);
Loading history...
38
39
        $this->assertEquals($processResult, $this->key->parse($key, $index));
40
    }
41
42
    public function testInvalidArgumentExceptionBubblesUpFromProcessMatches()
43
    {
44
        $exception = new InvalidArgumentException('nth must be equal to or larger than 1');
45
46
        /* @noinspection PhpUndefinedMethodInspection */
47
        Phake::expect($this->key, 1)->processMatches(Phake::anyParameters())->thenThrow($exception);
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

47
        Phake::expect(/** @scrutinizer ignore-type */ $this->key, 1)->processMatches(Phake::anyParameters())->thenThrow($exception);
Loading history...
48
49
        $this->expectException(get_class($exception));
50
        $this->expectExceptionMessage($exception->getMessage());
51
52
        $this->key->parse('0th thing');
53
    }
54
}
55