Passed
Branch scrutinizer_new_php_analysis (b739aa)
by Donald
01:58
created

BuildTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 46
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testBuildKeyBuildsValidKeyAndIndexCombinations() 0 8 1
A setUp() 0 6 1
A validKeyAndIndexCombinationsDataProvider() 0 11 1
1
<?php namespace Chekote\NounStore\Key;
2
3
use Chekote\Phake\Phake;
4
5
/**
6
 * @covers \Chekote\NounStore\Key::build()
7
 */
8
class BuildTest extends KeyTest
9
{
10
    public function setUp()
11
    {
12
        parent::setUp();
13
14
        /* @noinspection PhpUndefinedMethodInspection */
15
        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

15
        Phake::when(/** @scrutinizer ignore-type */ $this->key)->build(Phake::anyParameters())->thenCallParent();
Loading history...
16
    }
17
18
    /**
19
     * Tests that calling the method with valid key and index combinations works correctly.
20
     *
21
     * @dataProvider validKeyAndIndexCombinationsDataProvider
22
     * @param string $key      the key to use for the build
23
     * @param int    $index    the index to use for the build
24
     * @param int    $nth      the nth that we expect build to pass to getOrdinal()
25
     * @param string $ordinal  the ordinal that the mocked getOrdinal() should return
26
     * @param string $expected the expected resulting key
27
     */
28
    public function testBuildKeyBuildsValidKeyAndIndexCombinations($key, $index, $nth, $ordinal, $expected)
29
    {
30
        /* @noinspection PhpUndefinedFieldInspection */
31
        Phake::when($this->key)->getOrdinal($nth)->thenReturn($ordinal);
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

31
        Phake::when(/** @scrutinizer ignore-type */ $this->key)->getOrdinal($nth)->thenReturn($ordinal);
Loading history...
32
33
        $actual = $this->key->build($key, $index);
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

33
        /** @scrutinizer ignore-call */ 
34
        $actual = $this->key->build($key, $index);

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...
34
35
        $this->assertEquals($expected, $actual);
36
    }
37
38
    /**
39
     * Provides examples of valid key and index pairs with expected build results.
40
     *
41
     * @return array
42
     */
43
    public function validKeyAndIndexCombinationsDataProvider()
44
    {
45
        return [
46
            // key   index  nth,  ordinal, expected result
47
            ['Thing', null, null, null,    'Thing'],
48
            ['Thing',    0,    1, 'st',    '1st Thing'],
49
            ['Thing',    1,    2, 'nd',    '2nd Thing'],
50
            ['Thing',    2,    3, 'rd',    '3rd Thing'],
51
            ['Thing',    3,    4, 'th',    '4th Thing'],
52
            ['Thing',    4,    5, 'th',    '5th Thing'],
53
            ['Thing',  477,  478, 'th',    '478th Thing'],
54
        ];
55
    }
56
}
57