BuildTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testInvalidArgumentExceptionBubblesUpFromGetOrdinal() 0 15 1
A testNonNullIndexReturnsModifiedKey() 0 10 1
A setUp() 0 6 1
A testNullIndexReturnsUnmodifiedKey() 0 5 1
1
<?php namespace Unit\Chekote\NounStore\Key;
2
3
use InvalidArgumentException;
4
use Unit\Chekote\Phake\Phake;
5
6
/**
7
 * @covers \Chekote\NounStore\Key::build()
8
 */
9
class BuildTest extends KeyTestCase
10
{
11
    public function setUp(): void
12
    {
13
        parent::setUp();
14
15
        /* @noinspection PhpUndefinedMethodInspection */
16
        Phake::when($this->key)->build(Phake::anyParameters())->thenCallParent();
17
    }
18
19
    public function testNullIndexReturnsUnmodifiedKey(): void
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 Unit\Chekote\NounStore\Assert\KeyPhake. ( 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...
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(): void
27
    {
28
        $key = 'Thing';
29
        $index = 18;
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 Unit\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...
34
35
        $this->assertEquals('19th Thing', $this->key->build($key, $index));
36
    }
37
38
    public function testInvalidArgumentExceptionBubblesUpFromGetOrdinal(): void
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);
48
49
        $this->expectException(get_class($exception));
50
        $this->expectExceptionMessage($exception->getMessage());
51
52
        $this->key->build($key, $index);
53
    }
54
}
55