| 1 |  |  | <?php namespace Chekote\NounStore\Assert; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | use Chekote\NounStore\Key\KeyTest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use Chekote\Phake\Phake; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use InvalidArgumentException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use OutOfBoundsException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use RuntimeException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @covers \Chekote\NounStore\Assert::keyValueContains() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | class KeyValueContainsTest extends AssertTest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     public function setUp() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |         parent::setUp(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |         /* @noinspection PhpUndefinedMethodInspection */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |         Phake::when($this->assert)->keyValueContains(Phake::anyParameters())->thenCallParent(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     public function testInvalidArgumentExceptionBubblesUpFromKeyExists() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         $value = 'Some Value'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         $exception = new InvalidArgumentException('Key syntax is invalid'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         /* @noinspection PhpUndefinedMethodInspection */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         Phake::expect($this->assert, 1)->keyExists(KeyTest::INVALID_KEY)->thenThrow($exception); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         $this->expectException(get_class($exception)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         $this->expectExceptionMessage($exception->getMessage()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $this->assert->keyValueContains(KeyTest::INVALID_KEY, $value); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     // An invalid key should not get past keyExists(), so this should never actually be possible. But we test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     // the behavior here to ensure that our method behaves correctly should the impossible ever occur. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     public function testInvalidArgumentExceptionBubblesUpFromKeyValueContains() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $value = 'Some Value'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $exception = new InvalidArgumentException('Key syntax is invalid'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         /* @noinspection PhpUndefinedMethodInspection */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |             Phake::expect($this->assert, 1)->keyExists(KeyTest::INVALID_KEY)->thenReturn(true); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             Phake::expect($this->store, 1)->keyValueContains(KeyTest::INVALID_KEY, $value)->thenThrow($exception); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         $this->expectException(get_class($exception)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $this->expectExceptionMessage($exception->getMessage()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         $this->assert->keyValueContains(KeyTest::INVALID_KEY, $value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |     public function testMissingKeyThrowsOutOfBoundsException() | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |         $key = '10th Thing'; | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |         $value = 'Some Value'; | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |         $exception = new OutOfBoundsException("Entry '$key' was not found in the store."); | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |         /* @noinspection PhpUndefinedMethodInspection */ | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |         Phake::expect($this->assert, 1)->keyExists($key)->thenThrow($exception); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |         $this->expectException(get_class($exception)); | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |         $this->expectExceptionMessage($exception->getMessage()); | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |         $this->assert->keyValueContains($key, $value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     public function testFailedMatchThrowsRuntimeException() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         $key = '10th Thing'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         $value = 'Some Value'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $exception = new RuntimeException("Entry '$key' does not contain '$value'"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         /* @noinspection PhpUndefinedMethodInspection */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |             Phake::expect($this->assert, 1)->keyExists($key)->thenReturn(null); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |             Phake::expect($this->store, 1)->keyValueContains($key, $value)->thenReturn(false); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         $this->expectException(get_class($exception)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         $this->expectExceptionMessage($exception->getMessage()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         $this->assert->keyValueContains($key, $value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     public function testSuccessfulMatchThrowsNoException() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         $key = '10th Thing'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         $value = 'Some Value'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         /* @noinspection PhpUndefinedMethodInspection */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |             Phake::expect($this->assert, 1)->keyExists($key)->thenReturn(null); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |             Phake::expect($this->store, 1)->keyValueContains($key, $value)->thenReturn(true); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         $this->assert->keyValueContains($key, $value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 101 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 102 |  |  |  |