Passed
Pull Request — master (#16)
by Donald
01:47
created

testInvalidArgumentExceptionBubblesUpFromGetOrdinal()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 17
rs 9.4285
cc 1
eloc 8
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::when($this->key)->getOrdinal($nth)->thenReturn('th');
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

33
        Phake::when(/** @scrutinizer ignore-type */ $this->key)->getOrdinal($nth)->thenReturn('th');
Loading history...
34
35
        $this->assertEquals('10th Thing', $this->key->build($key, $index));
36
37
        /* @noinspection PhpUndefinedMethodInspection */
38
        Phake::verify($this->key)->getOrdinal($nth);
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::verify() 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

38
        Phake::verify(/** @scrutinizer ignore-type */ $this->key)->getOrdinal($nth);
Loading history...
39
    }
40
41
    public function testInvalidArgumentExceptionBubblesUpFromGetOrdinal()
42
    {
43
        $key = 'Thing';
44
        $index = -2;
45
        $nth = $index + 1;
46
47
        $exception = new InvalidArgumentException('$nth must be a positive number');
48
49
        /* @noinspection PhpUndefinedMethodInspection */
50
        Phake::when($this->key)->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 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

50
        Phake::when(/** @scrutinizer ignore-type */ $this->key)->getOrdinal($nth)->thenThrow($exception);
Loading history...
51
52
        $this->assertException($exception, function () use ($key, $index) {
53
            $this->key->build($key, $index);
54
        });
55
56
        /* @noinspection PhpUndefinedMethodInspection */
57
        Phake::verify($this->key)->getOrdinal($nth);
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::verify() 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

57
        Phake::verify(/** @scrutinizer ignore-type */ $this->key)->getOrdinal($nth);
Loading history...
58
    }
59
}
60