| 1 |  |  | <?php namespace Unit\Chekote\NounStore\Store; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | use InvalidArgumentException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use Unit\Chekote\NounStore\Key\KeyTest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Unit\Chekote\Phake\Phake; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @covers \Chekote\NounStore\Store::keyValueContains() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | class KeyValueContainsTest extends StoreTest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     public function setUp() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |         parent::setUp(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |         /* @noinspection PhpUndefinedMethodInspection */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |         Phake::when($this->store)->keyValueContains(Phake::anyParameters())->thenCallParent(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |     public function testInvalidArgumentExceptionBubblesUpFromGet() | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |         $exception = new InvalidArgumentException('Key syntax is invalid'); | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |         /* @noinspection PhpUndefinedMethodInspection */ | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |         Phake::expect($this->store, 1)->get(KeyTest::INVALID_KEY)->thenThrow($exception); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |         $this->expectException(get_class($exception)); | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |         $this->expectExceptionMessage($exception->getMessage()); | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |         $this->store->keyValueContains(KeyTest::INVALID_KEY, "Doesn't matter"); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     public function returnDataProvider() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             // storedValue,      checkedValue, expectedResult | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |             [ 'This is a value', 'is a',       true           ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             [ 'This is a value', 'words',      false          ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * @dataProvider returnDataProvider | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      * @param string $storedValue    the value that should be in the store and will be returned by the mocked get() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      * @param string $checkedValue   the value that will be passed to keyValueContains() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      * @param bool   $expectedResult the expected results from keyExists() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     public function testReturn($storedValue, $checkedValue, $expectedResult) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $key = StoreTest::KEY; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $parsedKey = $key; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         $parsedIndex = null; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         /* @noinspection PhpUndefinedMethodInspection */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         Phake::expect($this->store, 1)->get($parsedKey)->thenReturn($storedValue); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $this->assertEquals($expectedResult, $this->store->keyValueContains($key, $checkedValue)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 59 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 60 |  |  |  |