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

GetOrdinalTest::testFailureScenario()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 3
1
<?php namespace Chekote\NounStore\Key;
2
3
use Chekote\Phake\Phake;
4
use InvalidArgumentException;
5
6
/**
7
 * @covers \Chekote\NounStore\Key::getOrdinal()
8
 */
9
class GetOrdinalTest extends KeyTest
10
{
11
    public function setUp()
12
    {
13
        parent::setUp();
14
15
        /* @noinspection PhpUndefinedMethodInspection */
16
        Phake::when($this->key)->getOrdinal(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)->getOrdinal(Phake::anyParameters())->thenCallParent();
Loading history...
17
    }
18
19
    public function successScenariosDataProvider()
20
    {
21
        return [
22
        //   nth  expected
23
            [0,   'th'],
24
            [1,   'st'],
25
            [2,   'nd'],
26
            [3,   'rd'],
27
            [4,   'th'],
28
            [5,   'th'],
29
            [6,   'th'],
30
            [7,   'th'],
31
            [8,   'th'],
32
            [9,   'th'],
33
            [10,  'th'],
34
            [11,  'th'],
35
            [12,  'th'],
36
            [13,  'th'],
37
            [14,  'th'],
38
            [21,  'st'],
39
            [22,  'nd'],
40
            [23,  'rd'],
41
            [24,  'th'],
42
            [101, 'st'],
43
            [102, 'nd'],
44
            [103, 'rd'],
45
            [104, 'th'],
46
        ];
47
    }
48
49
    public function failureScenariosDataProvider()
50
    {
51
        return [
52
        //   nth  exception class                  exception message
53
            [-1,  InvalidArgumentException::class, '$nth must be a positive number'],
54
        ];
55
    }
56
57
    /**
58
     * Executes a success scenario against the method.
59
     *
60
     * @dataProvider successScenariosDataProvider
61
     * @param int    $nth      the nth to pass to the method.
62
     * @param string $expected the ordinal expected from the method.
63
     */
64
    public function testSuccessScenario($nth, $expected)
65
    {
66
        $actual = $this->key->getOrdinal($nth);
0 ignored issues
show
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

66
        /** @scrutinizer ignore-call */ 
67
        $actual = $this->key->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...
67
68
        $this->assertEquals($expected, $actual);
69
    }
70
71
    /**
72
     * Executes a failure scenario against the method.
73
     *
74
     * @dataProvider failureScenariosDataProvider
75
     * @param int    $nth              the nth to pass to the method.
76
     * @param string $exceptionClass   the expected class of the exception.
77
     * @param string $exceptionMessage the expected message of the exception.
78
     */
79
    public function testFailureScenario($nth, $exceptionClass, $exceptionMessage)
80
    {
81
        $this->expectException($exceptionClass);
82
        $this->expectExceptionMessage($exceptionMessage);
83
84
        $this->key->getOrdinal($nth);
85
    }
86
}
87