Passed
Push — master ( 19b79d...9475d5 )
by Donald
02:27
created

BuildTest::testNullIndexReturnsUnmodifiedKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
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::build()
8
 */
9
class BuildTest extends KeyTest
10
{
11
    public function setUp()
12
    {
13
        parent::setUp();
14
15
        /* @noinspection PhpUndefinedMethodInspection */
16
        Phake::when($this->key)->build(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)->build(Phake::anyParameters())->thenCallParent();
Loading history...
17
    }
18
19
    public function testNullIndexReturnsUnmodifiedKey()
20
    {
21
        $key = 'Thing';
22
23
        $this->assertEquals($key, $this->key->build($key, null));
0 ignored issues
show
Bug introduced by
The method build() 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

23
        $this->assertEquals($key, $this->key->/** @scrutinizer ignore-call */ build($key, null));

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...
24
    }
25
26
    public function testNonNullIndexReturnsModifiedKey()
27
    {
28
        $key = 'Thing';
29
        $index = 9;
30
        $nth = $index + 1;
31
32
        /* @noinspection PhpUndefinedMethodInspection */
33
        Phake::expect($this->key, 1)->getOrdinal($nth)->thenReturn('th');
0 ignored issues
show
Bug introduced by
The method getOrdinal() 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

33
        Phake::expect($this->key, 1)->/** @scrutinizer ignore-call */ getOrdinal($nth)->thenReturn('th');
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

33
        Phake::expect(/** @scrutinizer ignore-type */ $this->key, 1)->getOrdinal($nth)->thenReturn('th');
Loading history...
34
35
        $this->assertEquals('10th Thing', $this->key->build($key, $index));
36
    }
37
38
    public function testInvalidArgumentExceptionBubblesUpFromGetOrdinal()
39
    {
40
        $key = 'Thing';
41
        $index = -2;
42
        $nth = $index + 1;
43
44
        $exception = new InvalidArgumentException('$nth must be a positive number');
45
46
        /* @noinspection PhpUndefinedMethodInspection */
47
        Phake::expect($this->key, 1)->getOrdinal($nth)->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)->getOrdinal($nth)->thenThrow($exception);
Loading history...
48
49
        $this->expectException(get_class($exception));
50
        $this->expectExceptionMessage($exception->getMessage());
51
52
        $this->key->build($key, $index);
53
    }
54
}
55