| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace SubjectivePHPTest\Psr\Log; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use SubjectivePHP\Psr\Log\ExceptionExtractorTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @coversDefaultClass \SubjectivePHP\Psr\Log\ExceptionExtractorTrait | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * @covers ::<private> | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 10 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 11 |  |  | final class ExceptionExtractorTraitTest extends \PHPUnit\Framework\TestCase | 
            
                                                                        
                            
            
                                    
            
            
                | 12 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  |     use ExceptionExtractorTrait; | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |      * @param array  $context         The array containing the exception. | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |      * @param string $expectedType    The expected exception class. | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |      * @param string $expectedMessage The expected exception message. | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |      * @test | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |      * @covers ::getExceptionFromContext | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |      * @dataProvider provideDataWithException | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |      * @return void | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     public function getException(array $context, string $expectedType, string $expectedMessage) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         $exception = $this->getExceptionFromContext($context); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         $this->assertInstanceOf($expectedType, $exception); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         $this->assertSame($expectedMessage, $exception->getMessage()); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 31 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |      * @param array $context The array which does not contain a valid exception | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |      * @test | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |      * @covers ::getExceptionFromContext | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |      * @dataProvider provideDataWithoutException | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |      * @return void | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     public function getNull(array $context) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $this->assertNull($this->getExceptionFromContext($context)); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 45 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |      * Provides valid data containing exception values and expected results. | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |      * @return array | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     public function provideDataWithException() : array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             [['exception' => new \RuntimeException('a message')], '\\RuntimeException', 'a message'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |             [['exception' => new \TypeError('an error')], '\\ErrorException', 'an error'], | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         ]; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 58 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |      * Provides valid data containing invalid exception or no exception values and expected results. | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |      * @return array | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     public function provideDataWithoutException() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |             'null' => [['exception' => null]], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |             'string' => [['exception' => 'a message']], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |             'no exepting' => [[]], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         ]; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 72 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 73 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 74 |  |  |  | 
            
                        
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.