Getting the following error for an invalid callback in extension
registration is not helpful:
Fatal error: Uncaught exception 'InvalidArgumentException' with message
'Invalid callback provided' in /includes/config/ConfigFactory.php:108
Changed message to
Invalid callback '$1' provided
Added a test case for the instanceof part of the if
Change-Id: I425e2607b651c666336289c2c0d93730bb6312ed
*/
public function register( $name, $callback ) {
if ( !is_callable( $callback ) && !( $callback instanceof Config ) ) {
- throw new InvalidArgumentException( 'Invalid callback provided' );
+ if ( is_array( $callback ) ) {
+ $callback = '[ ' . implode( ', ', $callback ) . ' ]';
+ } elseif ( is_object( $callback ) ) {
+ $callback = 'instanceof ' . get_class( $callback );
+ }
+ throw new InvalidArgumentException( 'Invalid callback \'' . $callback . '\' provided' );
}
unset( $this->configs[$name] );
$factory->register( 'invalid', 'Invalid callback' );
}
+ /**
+ * @covers ConfigFactory::register
+ */
+ public function testRegisterInvalidInstance() {
+ $factory = new ConfigFactory();
+ $this->setExpectedException( InvalidArgumentException::class );
+ $factory->register( 'invalidInstance', new stdClass );
+ }
+
/**
* @covers ConfigFactory::register
*/