GetOrdinalTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testSuccessScenario() 0 3 1
A setUp() 0 6 1
A successScenariosDataProvider() 0 9 1
A failureScenariosDataProvider() 0 5 1
A testFailureScenario() 0 6 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::getOrdinal()
8
 */
9
class GetOrdinalTest extends KeyTestCase
10
{
11
    public function setUp(): void
12
    {
13
        parent::setUp();
14
15
        /* @noinspection PhpUndefinedMethodInspection */
16
        Phake::when($this->key)->getOrdinal(Phake::anyParameters())->thenCallParent();
17
    }
18
19
    public static function successScenariosDataProvider(): array
20
    {
21
        return [
22
            [0,   'th'], [1,   'st'], [2,   'nd'], [3,   'rd'],
23
            [4,   'th'], [5,   'th'], [6,   'th'], [7,   'th'],
24
            [8,   'th'], [9,   'th'], [10,  'th'], [11,  'th'],
25
            [12,  'th'], [13,  'th'], [14,  'th'], [21,  'st'],
26
            [22,  'nd'], [23,  'rd'], [24,  'th'], [101, 'st'],
27
            [102, 'nd'], [103, 'rd'], [104, 'th'],
28
        ];
29
    }
30
31
    public static function failureScenariosDataProvider(): array
32
    {
33
        return [
34
            //nth  exception class                  exception message
35
            [  -1, InvalidArgumentException::class, '$nth must be a positive number'],
36
        ];
37
    }
38
39
    /**
40
     * Executes a success scenario against the method.
41
     *
42
     * @dataProvider successScenariosDataProvider
43
     * @param int    $nth      the nth to pass to the method.
44
     * @param string $expected the ordinal expected from the method.
45
     */
46
    public function testSuccessScenario(int $nth, string $expected): void
47
    {
48
        $this->assertEquals($expected, $this->key->getOrdinal($nth));
0 ignored issues
show
Bug introduced by
The method getOrdinal() 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

48
        $this->assertEquals($expected, $this->key->/** @scrutinizer ignore-call */ getOrdinal($nth));

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 getOrdinal() 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

48
        $this->assertEquals($expected, $this->key->/** @scrutinizer ignore-call */ getOrdinal($nth));

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...
49
    }
50
51
    /**
52
     * Executes a failure scenario against the method.
53
     *
54
     * @dataProvider failureScenariosDataProvider
55
     * @param int    $nth              the nth to pass to the method.
56
     * @param string $exceptionClass   the expected class of the exception.
57
     * @param string $exceptionMessage the expected message of the exception.
58
     */
59
    public function testFailureScenario(int $nth, string $exceptionClass, string $exceptionMessage): void
60
    {
61
        $this->expectException($exceptionClass);
62
        $this->expectExceptionMessage($exceptionMessage);
63
64
        $this->key->getOrdinal($nth);
65
    }
66
}
67