| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | use DigiTickets\PHPUnit\ErrorHandler; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | class tests extends \PHPUnit\Framework\TestCase | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |     use ErrorHandler; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |     public function provideUserErrors() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |             ['Generated E_USER_ERROR', E_USER_ERROR], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |             ['Generated E_USER_WARNING', E_USER_WARNING], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |             ['Generated E_USER_NOTICE', E_USER_NOTICE], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |             ['Generated E_USER_DEPRECATED', E_USER_DEPRECATED], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     public function testAssertErrorHandler() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         $this->errorHandler(E_USER_NOTICE, 'Testing ErrorHandler', __FILE__, __LINE__, []); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         $this->assertError('Testing ErrorHandler', E_USER_NOTICE); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     public function testAssertError() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         $this->expectException(\PHPUnit\Framework\AssertionFailedError::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         $this->expectExceptionMessage('Error with level 1024 and message \'Unknown E_USER_WARNING\' not found in array'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         $this->assertError('Unknown E_USER_WARNING', E_USER_NOTICE); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     public function testPHPGeneratedNoticeIsCaptured() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $keys = [1, 2, 3]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $keys[1] = $keys[4]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $this->assertError('Undefined offset: 4', E_NOTICE); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |     public function testPHPGeneratedRecoverableErrorIsCaptured() | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |         require __DIR__ . '/_files/testClassForRecoverableError.php'; | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |         $it = new ArrayIterator(new testClassForRecoverableError()); | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |         $it->append('will not work'); | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |         $this->assertError('ArrayIterator::append(): Cannot append properties to objects, use ArrayIterator::offsetSet() instead', E_RECOVERABLE_ERROR); | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     public function testPHPGeneratedWarningIsCaptured() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $keys = [1, 2, 3]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $values = [1, 2, 3, 4]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         array_combine($keys, $values); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         $this->assertError('array_combine(): Both parameters should have an equal number of elements', E_WARNING); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * @dataProvider provideUserErrors | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * @param string $message | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      * @param int $errorType | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     public function testUserErrorsAreCaptured($message, $errorType) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         trigger_error($message, $errorType); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $this->assertError($message, $errorType); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     protected function setUp() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         // Set the error handler. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         $this->setUpErrorHandler(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 79 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 80 |  |  |  | 
            
                        
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.