Passed
Push — related_object ( 8af542 )
by Donald
03:06
created

testInvalidKeyThrowsInvalidArgumentException()   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
c 0
b 0
f 0
rs 10
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
        $this->expectException(InvalidArgumentException::class);
22
        $this->expectExceptionMessage('Key is not valid. Must match pattern ' . Key::REGEX_KEY);
23
24
        $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

24
        $this->key->/** @scrutinizer ignore-call */ 
25
                    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...
25
    }
26
27
    public function testValidKeyIsProcessed() {
28
        $key = "10th thing's address";
29
        $index = null;
30
31
        $pregResult = ["10th thing's address", '10th ', '10', 'thing', "'s address", 'address'];
32
        $processResult = ['thing', 9, 'address'];
33
34
        /* @noinspection PhpUndefinedMethodInspection */
35
        Phake::expect($this->key, 1)->processMatches($index, $pregResult)->thenReturn($processResult);
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

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

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

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