Skip to content

Commit 2949a6a

Browse files
committed
chore: add test
1 parent 2d513a8 commit 2949a6a

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

tests/GetModelRelationsTest.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
use BeyondCode\ErdGenerator\Tests\Models\Avatar;
88
use BeyondCode\ErdGenerator\Tests\Models\Comment;
99
use BeyondCode\ErdGenerator\Tests\Models\Post;
10+
use BeyondCode\ErdGenerator\Tests\Fixtures\ModelWithThrowingMethod;
1011
use BeyondCode\ErdGenerator\Tests\Models\User;
1112
use Illuminate\Support\Arr;
13+
use Illuminate\Support\Facades\Log;
1214
use PHPUnit\Framework\Attributes\Test;
1315

14-
1516
class GetModelRelationsTest extends TestCase
1617
{
17-
1818
#[Test]
1919
public function it_can_find_model_relations()
2020
{
@@ -69,4 +69,24 @@ public function it_will_ignore_a_relation_if_it_is_excluded_on_config()
6969
$this->assertNull(Arr::get($relations, 'posts'));
7070
}
7171

72+
#[Test]
73+
public function it_logs_debug_when_method_throws_exception()
74+
{
75+
Log::spy();
76+
77+
$finder = new RelationFinder();
78+
79+
$relations = $finder->getModelRelations(ModelWithThrowingMethod::class);
80+
81+
$this->assertCount(0, $relations);
82+
83+
Log::shouldHaveReceived('debug')
84+
->withArgs(function (string $message) {
85+
return str_contains($message, 'Could not analyze method')
86+
&& str_contains($message, 'throwingMethod')
87+
&& str_contains($message, 'Something went wrong');
88+
})
89+
->once();
90+
}
91+
7292
}

0 commit comments

Comments
 (0)