wordpress-develop/tests/phpunit/tests/functions/wpTriggerError.php
Sergey Biryukov 2a6b527f73 Tests: Improve the @group annotation accuracy and consistency.
Includes removing `.php` from some older group names, because most of the groups are no longer named based on the file containing the function, and sometimes functions move around, making the file-based group name inaccurate.

Props afercia, aristath, poena, SergeyBiryukov.
See #59647.

git-svn-id: https://develop.svn.wordpress.org/trunk@56971 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-19 13:51:04 +00:00

103 lines
2.9 KiB
PHP

<?php
/**
* Test cases for the `wp_trigger_error()` function.
*
* @since 6.4.0
*
* @group functions
*
* @covers ::wp_trigger_error
*/
class Tests_Functions_WpTriggerError extends WP_UnitTestCase {
/**
* @ticket 57686
*
* @dataProvider data_should_trigger_error
*
* @param string $function_name The function name to test.
* @param string $message The message to test.
* @param string $expected_message The expected error message.
*/
public function test_should_trigger_error( $function_name, $message, $expected_message ) {
$this->expectError();
$this->expectErrorMessage( $expected_message );
wp_trigger_error( $function_name, $message, E_USER_ERROR );
}
/**
* @ticket 57686
*
* @dataProvider data_should_trigger_error
*
* @param string $function_name The function name to test.
* @param string $message The message to test.
* @param string $expected_message The expected error message.
*/
public function test_should_trigger_warning( $function_name, $message, $expected_message ) {
$this->expectWarning();
$this->expectWarningMessage( $expected_message );
wp_trigger_error( $function_name, $message, E_USER_WARNING );
}
/**
* @ticket 57686
*
* @dataProvider data_should_trigger_error
*
* @param string $function_name The function name to test.
* @param string $message The message to test.
* @param string $expected_message The expected error message.
*/
public function test_should_trigger_notice( $function_name, $message, $expected_message ) {
$this->expectNotice();
$this->expectNoticeMessage( $expected_message );
wp_trigger_error( $function_name, $message );
}
/**
* @ticket 57686
*
* @dataProvider data_should_trigger_error
*
* @param string $function_name The function name to test.
* @param string $message The message to test.
* @param string $expected_message The expected error message.
*/
public function test_should_trigger_deprecation( $function_name, $message, $expected_message ) {
$this->expectDeprecation();
$this->expectDeprecationMessage( $expected_message );
wp_trigger_error( $function_name, $message, E_USER_DEPRECATED );
}
/**
* Data provider.
*
* @return array
*/
public function data_should_trigger_error() {
return array(
'function name and message are given' => array(
'function_name' => 'some_function',
'message' => 'expected the function name and message',
'expected_message' => 'some_function(): expected the function name and message',
),
'message is given' => array(
'function_name' => '',
'message' => 'expect only the message',
'expected_message' => 'expect only the message',
),
'function name is given' => array(
'function_name' => 'some_function',
'message' => '',
'expected_message' => 'some_function(): ',
),
);
}
}