Passed
Branch 2.0 (434547)
by Donald
04:28 queued 02:14
created

GetOrdinalTest::successScenariosDataProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 1
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::getOrdinal()
8
 */
9
class GetOrdinalTest extends KeyTest
10
{
11
    public static $successScenarioDataProvider = [
12
        //   nth  expected
13
        [0,   'th'],
14
        [1,   'st'],
15
        [2,   'nd'],
16
        [3,   'rd'],
17
        [4,   'th'],
18
        [5,   'th'],
19
        [6,   'th'],
20
        [7,   'th'],
21
        [8,   'th'],
22
        [9,   'th'],
23
        [11,  'th'],
24
        [12,  'th'],
25
        [13,  'th'],
26
        [21,  'st'],
27
        [22,  'nd'],
28
        [23,  'rd'],
29
        [24,  'th'],
30
    ];
31
32
    public function setUp()
33
    {
34
        parent::setUp();
35
36
        /* @noinspection PhpUndefinedMethodInspection */
37
        Phake::when($this->key)->getOrdinal(Phake::anyParameters())->thenCallParent();
38
    }
39
40
    public function successScenariosDataProvider()
41
    {
42
        return self::$successScenarioDataProvider;
43
    }
44
45
    public function failureScenariosDataProvider()
46
    {
47
        return [
48
        //   nth  exception class                  exception message
49
            [-1,  InvalidArgumentException::class, '$nth must be a positive number'],
50
        ];
51
    }
52
53
    /**
54
     * Executes a success scenario against the method.
55
     *
56
     * @dataProvider successScenariosDataProvider
57
     * @param int    $nth      the nth to pass to the method.
58
     * @param string $expected the ordinal expected from the method.
59
     */
60
    public function testSuccessScenario($nth, $expected)
61
    {
62
        $this->assertEquals($expected, $this->key->getOrdinal($nth));
63
    }
64
65
    /**
66
     * Executes a failure scenario against the method.
67
     *
68
     * @dataProvider failureScenariosDataProvider
69
     * @param int    $nth              the nth to pass to the method.
70
     * @param string $exceptionClass   the expected class of the exception.
71
     * @param string $exceptionMessage the expected message of the exception.
72
     */
73
    public function testFailureScenario($nth, $exceptionClass, $exceptionMessage)
74
    {
75
        $this->expectException($exceptionClass);
76
        $this->expectExceptionMessage($exceptionMessage);
77
78
        $this->key->getOrdinal($nth);
79
    }
80
}
81