Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.6] Rewrite BadMethodCallException messages for consistency and always include the FQN of the class that throws the exception #23232

Merged
merged 2 commits into from
Feb 20, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Illuminate/Database/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}
5 changes: 2 additions & 3 deletions src/Illuminate/Http/RedirectResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}
3 changes: 2 additions & 1 deletion src/Illuminate/Mail/Mailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}
3 changes: 2 additions & 1 deletion src/Illuminate/Routing/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}
3 changes: 2 additions & 1 deletion src/Illuminate/Routing/RouteRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}
6 changes: 4 additions & 2 deletions src/Illuminate/Support/Traits/Macroable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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];
Expand Down
3 changes: 2 additions & 1 deletion src/Illuminate/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}
3 changes: 2 additions & 1 deletion src/Illuminate/View/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion tests/Http/HttpRedirectResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Http/HttpResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Routing/RouteRegistrarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Support/SupportCarbonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/View/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down