From 6a76cd17c9997a3365ebe6a3a788444c22c97df6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gregorio=20Hern=C3=A1ndez=20Caso?= Date: Tue, 20 Feb 2018 16:24:16 +0100 Subject: [PATCH 1/2] Rewrite BadMethodCallException messages for consistency and always include the FQN of the class that generates the exception --- src/Illuminate/Database/Eloquent/Builder.php | 3 ++- src/Illuminate/Database/Query/Builder.php | 3 +-- src/Illuminate/Http/RedirectResponse.php | 5 ++--- src/Illuminate/Mail/Mailable.php | 3 ++- src/Illuminate/Routing/Controller.php | 3 ++- src/Illuminate/Routing/RouteRegistrar.php | 3 ++- src/Illuminate/Support/Traits/Macroable.php | 6 ++++-- src/Illuminate/Validation/Validator.php | 3 ++- src/Illuminate/View/View.php | 3 ++- 9 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Builder.php b/src/Illuminate/Database/Eloquent/Builder.php index 6dab7476047c..712c5d4b3f5b 100755 --- a/src/Illuminate/Database/Eloquent/Builder.php +++ b/src/Illuminate/Database/Eloquent/Builder.php @@ -1304,7 +1304,8 @@ public static function __callStatic($method, $parameters) } if (! isset(static::$macros[$method])) { - throw new BadMethodCallException("Method {$method} does not exist."); + $className = static::class; + throw new BadMethodCallException("Method {$className}::{$method} does not exist."); } if (static::$macros[$method] instanceof Closure) { diff --git a/src/Illuminate/Database/Query/Builder.php b/src/Illuminate/Database/Query/Builder.php index 0bc8d1871bfc..971cc3110c01 100755 --- a/src/Illuminate/Database/Query/Builder.php +++ b/src/Illuminate/Database/Query/Builder.php @@ -2508,7 +2508,6 @@ public function __call($method, $parameters) } $className = static::class; - - throw new BadMethodCallException("Call to undefined method {$className}::{$method}()"); + throw new BadMethodCallException("Method {$className}::{$method} does not exist."); } } diff --git a/src/Illuminate/Http/RedirectResponse.php b/src/Illuminate/Http/RedirectResponse.php index 0a462ffdb6e9..f3f58f3037ae 100755 --- a/src/Illuminate/Http/RedirectResponse.php +++ b/src/Illuminate/Http/RedirectResponse.php @@ -231,8 +231,7 @@ public function __call($method, $parameters) return $this->with(Str::snake(substr($method, 4)), $parameters[0]); } - throw new BadMethodCallException( - "Method [$method] does not exist on Redirect." - ); + $className = static::class; + throw new BadMethodCallException("Method {$className}::{$method} does not exist."); } } diff --git a/src/Illuminate/Mail/Mailable.php b/src/Illuminate/Mail/Mailable.php index 5a412c90a900..40eff06586ac 100644 --- a/src/Illuminate/Mail/Mailable.php +++ b/src/Illuminate/Mail/Mailable.php @@ -718,6 +718,7 @@ public function __call($method, $parameters) return $this->with(Str::snake(substr($method, 4)), $parameters[0]); } - throw new BadMethodCallException("Method [$method] does not exist on mailable."); + $className = static::class; + throw new BadMethodCallException("Method {$className}::{$method} does not exist."); } } diff --git a/src/Illuminate/Routing/Controller.php b/src/Illuminate/Routing/Controller.php index bf4c8f1847f9..039d7a361b29 100644 --- a/src/Illuminate/Routing/Controller.php +++ b/src/Illuminate/Routing/Controller.php @@ -65,6 +65,7 @@ public function callAction($method, $parameters) */ public function __call($method, $parameters) { - throw new BadMethodCallException("Method [{$method}] does not exist on [".get_class($this).'].'); + $className = static::class; + throw new BadMethodCallException("Method {$className}::{$method} does not exist."); } } diff --git a/src/Illuminate/Routing/RouteRegistrar.php b/src/Illuminate/Routing/RouteRegistrar.php index 58acdf2fe549..4ae0a9bbfdf7 100644 --- a/src/Illuminate/Routing/RouteRegistrar.php +++ b/src/Illuminate/Routing/RouteRegistrar.php @@ -175,6 +175,7 @@ public function __call($method, $parameters) return $this->attribute($method, $parameters[0]); } - throw new BadMethodCallException("Method [{$method}] does not exist."); + $className = static::class; + throw new BadMethodCallException("Method {$className}::{$method} does not exist."); } } diff --git a/src/Illuminate/Support/Traits/Macroable.php b/src/Illuminate/Support/Traits/Macroable.php index a7703b145cbb..f59ae2a9c90c 100644 --- a/src/Illuminate/Support/Traits/Macroable.php +++ b/src/Illuminate/Support/Traits/Macroable.php @@ -71,7 +71,8 @@ public static function hasMacro($name) public static function __callStatic($method, $parameters) { if (! static::hasMacro($method)) { - throw new BadMethodCallException("Method {$method} does not exist."); + $className = static::class; + throw new BadMethodCallException("Method {$className}::{$method} does not exist."); } if (static::$macros[$method] instanceof Closure) { @@ -93,7 +94,8 @@ public static function __callStatic($method, $parameters) public function __call($method, $parameters) { if (! static::hasMacro($method)) { - throw new BadMethodCallException("Method {$method} does not exist."); + $className = static::class; + throw new BadMethodCallException("Method {$className}::{$method} does not exist."); } $macro = static::$macros[$method]; diff --git a/src/Illuminate/Validation/Validator.php b/src/Illuminate/Validation/Validator.php index 2c85af8b1905..8e5f5a8ad863 100755 --- a/src/Illuminate/Validation/Validator.php +++ b/src/Illuminate/Validation/Validator.php @@ -1137,6 +1137,7 @@ public function __call($method, $parameters) return $this->callExtension($rule, $parameters); } - throw new BadMethodCallException("Method [$method] does not exist."); + $className = static::class; + throw new BadMethodCallException("Method {$className}::{$method} does not exist."); } } diff --git a/src/Illuminate/View/View.php b/src/Illuminate/View/View.php index 496eb6cbd198..d9fac2241bac 100755 --- a/src/Illuminate/View/View.php +++ b/src/Illuminate/View/View.php @@ -396,7 +396,8 @@ public function __unset($key) public function __call($method, $parameters) { if (! Str::startsWith($method, 'with')) { - throw new BadMethodCallException("Method [$method] does not exist on view."); + $className = static::class; + throw new BadMethodCallException("Method {$className}::{$method} does not exist."); } return $this->with(Str::camel(substr($method, 4)), $parameters[0]); From c29871eebeea3a9d0ec4f7f431f1732ae37e8751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gregorio=20Hern=C3=A1ndez=20Caso?= Date: Tue, 20 Feb 2018 16:34:24 +0100 Subject: [PATCH 2/2] BadMethodCallException tests messages update --- tests/Http/HttpRedirectResponseTest.php | 2 +- tests/Http/HttpResponseTest.php | 2 +- tests/Routing/RouteRegistrarTest.php | 2 +- tests/Support/SupportCarbonTest.php | 4 ++-- tests/View/ViewTest.php | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Http/HttpRedirectResponseTest.php b/tests/Http/HttpRedirectResponseTest.php index b2e781b94f0c..b8dab27be17c 100755 --- a/tests/Http/HttpRedirectResponseTest.php +++ b/tests/Http/HttpRedirectResponseTest.php @@ -121,7 +121,7 @@ public function testMagicCall() /** * @expectedException \BadMethodCallException - * @expectedExceptionMessage Method [doesNotExist] does not exist on Redirect. + * @expectedExceptionMessage Method Illuminate\Http\RedirectResponse::doesNotExist does not exist. */ public function testMagicCallException() { diff --git a/tests/Http/HttpResponseTest.php b/tests/Http/HttpResponseTest.php index d31f905bc4a5..82bb5bce9cf9 100755 --- a/tests/Http/HttpResponseTest.php +++ b/tests/Http/HttpResponseTest.php @@ -189,7 +189,7 @@ public function testMagicCall() /** * @expectedException \BadMethodCallException - * @expectedExceptionMessage Method [doesNotExist] does not exist on Redirect. + * @expectedExceptionMessage Method Illuminate\Http\RedirectResponse::doesNotExist does not exist. */ public function testMagicCallException() { diff --git a/tests/Routing/RouteRegistrarTest.php b/tests/Routing/RouteRegistrarTest.php index c4c2c5b29f6f..3a239ddcb047 100644 --- a/tests/Routing/RouteRegistrarTest.php +++ b/tests/Routing/RouteRegistrarTest.php @@ -201,7 +201,7 @@ public function testCanRegisterGroupWithDomainAndNamePrefix() /** * @expectedException \BadMethodCallException - * @expectedExceptionMessage Method [missing] does not exist. + * @expectedExceptionMessage Method Illuminate\Routing\RouteRegistrar::missing does not exist. */ public function testRegisteringNonApprovedAttributesThrows() { diff --git a/tests/Support/SupportCarbonTest.php b/tests/Support/SupportCarbonTest.php index 6bb1a1812ea0..186e7baf8a0c 100644 --- a/tests/Support/SupportCarbonTest.php +++ b/tests/Support/SupportCarbonTest.php @@ -58,7 +58,7 @@ public function testCarbonIsMacroableWhenCalledStatically() /** * @expectedException \BadMethodCallException - * @expectedExceptionMessage Method nonExistingStaticMacro does not exist. + * @expectedExceptionMessage Method Illuminate\Support\Carbon::nonExistingStaticMacro does not exist. */ public function testCarbonRaisesExceptionWhenStaticMacroIsNotFound() { @@ -67,7 +67,7 @@ public function testCarbonRaisesExceptionWhenStaticMacroIsNotFound() /** * @expectedException \BadMethodCallException - * @expectedExceptionMessage Method nonExistingMacro does not exist. + * @expectedExceptionMessage Method Illuminate\Support\Carbon::nonExistingMacro does not exist. */ public function testCarbonRaisesExceptionWhenMacroIsNotFound() { diff --git a/tests/View/ViewTest.php b/tests/View/ViewTest.php index fd203d713baa..ba68eb1815ef 100755 --- a/tests/View/ViewTest.php +++ b/tests/View/ViewTest.php @@ -165,7 +165,7 @@ public function testViewMagicMethods() /** * @expectedException \BadMethodCallException - * @expectedExceptionMessage Method [badMethodCall] does not exist on view. + * @expectedExceptionMessage Method Illuminate\View\View::badMethodCall does not exist. */ public function testViewBadMethod() {