Skip to content

Commit

Permalink
throw LogicException
Browse files Browse the repository at this point in the history
  • Loading branch information
cesargb committed Aug 10, 2018
1 parent 735cf7a commit e9b6ed0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
10 changes: 4 additions & 6 deletions src/CascadeDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Cesargb\Database\Support;

use Exception;
use LogicException;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\Relations\MorphToMany;

Expand All @@ -13,8 +13,6 @@ trait CascadeDelete
*
* Listen for the deleted event of a model, and run
* the delete operation for morphs configured relationship methods.
*
* @throws \LogicException
*/
protected static function bootCascadeDelete()
{
Expand All @@ -35,13 +33,13 @@ protected static function bootCascadeDelete()
* Fetch the valids cascading morphs deletes for this model.
*
* @return array
* @throws \Exception
* @throws \LogicException
*/
protected function getCascadeDeleteMorphValid()
{
return array_filter($this->getCascadeDeleteMorph(), function ($method) {
if (! method_exists($this, $method)) {
throw new Exception(sprintf(
throw new LogicException(sprintf(
'The class %s not have the method %s',
self::class,
$method
Expand All @@ -53,7 +51,7 @@ protected function getCascadeDeleteMorphValid()
$relation = $this->$method();

if (! $relation instanceof MorphMany && ! $relation instanceof MorphToMany) {
throw new Exception(sprintf(
throw new LogicException(sprintf(
'The relation %s must return an object of type %s or %s',
$method,
MorphMany::class,
Expand Down
6 changes: 3 additions & 3 deletions tests/CascadeDeleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Tests;

use Exception;
use LogicException;
use Tests\Models\Photo;
use Tests\Models\Video;
use Tests\Models\BadModel;
Expand Down Expand Up @@ -66,7 +66,7 @@ public function test_it_can_delete_relations_with_morph_to_many()
}

/**
* @expectedException Exception
* @expectedException LogicException
* @expectedExceptionMessage The class Tests\Models\BadModel not have the method bad_method
*/
public function test_get_exception_if_method_not_exists()
Expand All @@ -75,7 +75,7 @@ public function test_get_exception_if_method_not_exists()
}

/**
* @expectedException Exception
* @expectedException LogicException
* @expectedExceptionMessage The relation bad_method must return an object of type Illuminate\Database\Eloquent\Relations\MorphMany or Illuminate\Database\Eloquent\Relations\MorphToMany
*/
public function test_get_exception_if_method_not_return_relation_morph()
Expand Down

0 comments on commit e9b6ed0

Please sign in to comment.