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