Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion collectors/php_errors.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,14 @@ public function error_handler( $errno, $message, $file = null, $line = null, $co
* Filters the PHP error handler return value. This can be used to control whether or not the default error
* handler is called after Query Monitor's.
*
* Return true to stop further error handling, false to run the normal error handler.
*
* @since 2.7.0
*
* @param bool $return_value Error handler return value. Default false.
*/
return apply_filters( 'qm/collect/php_errors_return_value', false );
return apply_filters( 'qm/collect/php_errors_return_value', false )
|| ( is_callable( $this->previous_error_handler ) && call_user_func_array( $this->previous_error_handler, func_get_args() ) );

}

Expand Down
32 changes: 32 additions & 0 deletions tests/integration/CollectorPhpErrorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,36 @@ function testItWillFilterNoticesFromPlugin(): void {
self::assertArrayNotHasKey( 'warning', $actual->silenced );
self::assertEquals( 1, count( $actual->silenced['notice'] ) );
}

function testItReturnsFalseWhenNoPreviousErrorHandler(): void {
$result = $this->collector->error_handler( E_WARNING, 'test' );

self::assertFalse( $result );
}

function testItCallsFilterForErrorHandlerResult(): void {
add_filter( 'qm/collect/php_errors_return_value', '__return_true' );

$result = $this->collector->error_handler( E_WARNING, 'test' );

self::assertTrue( $result );
}

function testItCallsPreviousErrorHandler(): void {
// Test needs the previous error handler set before the sut is set up.
ini_set( 'display_errors', '0' );
$this->collector->set_up();
$this->collector->tear_down();

set_error_handler(function( $errno, $message, $file = null, $line = null, $context = null, $do_trace = true ) {
return true;
});

$this->collector = new \QM_Collector_PHP_Errors();
$this->collector->set_up();

$result = $this->collector->error_handler( E_WARNING, 'test' );

self::assertTrue( $result );
}
}