| 1 |  |  | <?php namespace Unit\Chekote\NounStore\Key; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | use InvalidArgumentException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use Unit\Chekote\Phake\Phake; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @covers \Chekote\NounStore\Key::parse() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | class ParseTest extends KeyTest | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 10 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 11 |  |  |     public function setUp() | 
            
                                                                        
                            
            
                                    
            
            
                | 12 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  |         parent::setUp(); | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |         /* @noinspection PhpUndefinedMethodInspection */ | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |         Phake::when($this->key)->parse(Phake::anyParameters())->thenCallParent(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     public function testHappyPath() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         $key = "2nd Customer's 4th Car"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         $splitNouns = ['2nd Customer', '4th Car']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         $parsedKey = [['Customer', 1], ['Car', 3]]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         /* @noinspection PhpUndefinedMethodInspection */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |             Phake::expect($this->key, 1)->splitPossessions($key)->thenReturn($splitNouns); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |             Phake::expect($this->key, 1)->parseNoun($splitNouns[0])->thenReturn($parsedKey[0]); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |             Phake::expect($this->key, 1)->parseNoun($splitNouns[1])->thenReturn($parsedKey[1]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $this->assertEquals($parsedKey, $this->key->parse($key)); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     public function testInvalidArgumentExceptionBubblesUpFromParseNoun() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $invalidKey = "Customer's's Car"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $splitNouns = ["Customer's", 'Car']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $exception = new InvalidArgumentException('Key syntax is invalid'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         /* @noinspection PhpUndefinedMethodInspection */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |             Phake::expect($this->key, 1)->splitPossessions($invalidKey)->thenReturn($splitNouns); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |             Phake::expect($this->key, 1)->parseNoun($splitNouns[0])->thenThrow($exception); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         $this->expectException(get_class($exception)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $this->expectExceptionMessage($exception->getMessage()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $this->key->parse($invalidKey); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 52 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 53 |  |  |  |