From 1e193a2f4c9519ddbddad680e7f35c74098c0e72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20Guimar=C3=A3es?= Date: Sun, 9 Apr 2017 23:08:53 -0300 Subject: [PATCH 1/2] Show method name on invalid relationship LogicException --- src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php | 4 ++-- tests/Database/DatabaseEloquentModelTest.php | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php b/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php index 13f10370a10d..8d4be691c4fe 100644 --- a/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php +++ b/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php @@ -400,8 +400,8 @@ protected function getRelationshipFromMethod($method) $relation = $this->$method(); if (! $relation instanceof Relation) { - throw new LogicException('Relationship method must return an object of type ' - .'Illuminate\Database\Eloquent\Relations\Relation'); + throw new LogicException($method.' relationship method must return an object of type ' + .Relation::class); } return tap($relation->getResults(), function ($results) use ($method) { diff --git a/tests/Database/DatabaseEloquentModelTest.php b/tests/Database/DatabaseEloquentModelTest.php index 51c563e7dfac..2d5d07c28919 100755 --- a/tests/Database/DatabaseEloquentModelTest.php +++ b/tests/Database/DatabaseEloquentModelTest.php @@ -1275,6 +1275,7 @@ public function testRemoveMultipleObservableEvents() /** * @expectedException LogicException + * @expectedExceptionMessage incorrectRelationStub relationship method must return an object of type Illuminate\Database\Eloquent\Relations\Relation */ public function testGetModelAttributeMethodThrowsExceptionIfNotRelation() { From 2c53918543f7fdce6982245e50d1a847ff35f4ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20Guimar=C3=A3es?= Date: Sun, 9 Apr 2017 23:12:55 -0300 Subject: [PATCH 2/2] show class name --- src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php | 2 +- tests/Database/DatabaseEloquentModelTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php b/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php index 8d4be691c4fe..e506db42b7af 100644 --- a/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php +++ b/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php @@ -400,7 +400,7 @@ protected function getRelationshipFromMethod($method) $relation = $this->$method(); if (! $relation instanceof Relation) { - throw new LogicException($method.' relationship method must return an object of type ' + throw new LogicException(get_class($this).'::'.$method.' relationship method must return an object of type ' .Relation::class); } diff --git a/tests/Database/DatabaseEloquentModelTest.php b/tests/Database/DatabaseEloquentModelTest.php index 2d5d07c28919..f965bfd33bf0 100755 --- a/tests/Database/DatabaseEloquentModelTest.php +++ b/tests/Database/DatabaseEloquentModelTest.php @@ -1275,7 +1275,7 @@ public function testRemoveMultipleObservableEvents() /** * @expectedException LogicException - * @expectedExceptionMessage incorrectRelationStub relationship method must return an object of type Illuminate\Database\Eloquent\Relations\Relation + * @expectedExceptionMessage Illuminate\Tests\Database\EloquentModelStub::incorrectRelationStub relationship method must return an object of type Illuminate\Database\Eloquent\Relations\Relation */ public function testGetModelAttributeMethodThrowsExceptionIfNotRelation() {