Skip to content
Merged
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
9 changes: 9 additions & 0 deletions php/class-wp-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,8 @@ public static function print_value( $value, $assoc_args = array() ) {
* Convert a WP_Error or Exception into a string
*
* @param mixed $errors
* @throws \InvalidArgumentException
*
* @return string
*/
public static function error_to_string( $errors ) {
Expand Down Expand Up @@ -1010,6 +1012,13 @@ public static function error_to_string( $errors ) {
if ( interface_exists( 'Throwable' ) && ( $errors instanceof \Throwable ) || ( $errors instanceof \Exception ) ) {
return get_class( $errors ) . ': ' . $errors->getMessage();
}

throw new \InvalidArgumentException(
sprintf(
"Unsupported argument type passed to WP_CLI::error_to_string(): '%s'",
gettype( $errors )
)
);
}

/**
Expand Down
5 changes: 5 additions & 0 deletions tests/test-wp-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ class WP_CLI_Test extends PHPUnit_Framework_TestCase {
public function testGetPHPBinary() {
$this->assertSame( WP_CLI\Utils\get_php_binary(), WP_CLI::get_php_binary() );
}

public function testErrorToString() {
$this->setExpectedException( 'InvalidArgumentException', "Unsupported argument type passed to WP_CLI::error_to_string(): 'boolean'" );
WP_CLI::error_to_string( true );
}
}