Skip to content

Commit 1ef559c

Browse files
committed
make exception more precise
1 parent 5203dbf commit 1ef559c

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/Translatable/Translatable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public function getTranslationOrNew(?string $locale = null): Model
242242
public function getTranslationOrFail(string $locale): Model
243243
{
244244
if (($translation = $this->getTranslation($locale, false)) === null) {
245-
throw new ModelNotFoundException();
245+
throw (new ModelNotFoundException)->setModel($this->getTranslationModelName(), $locale);
246246
}
247247

248248
return $translation;

tests/TranslatableTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,12 +418,14 @@ public function it_has_methods_that_return_always_a_translation(): void
418418
/** @test */
419419
public function it_throws_an_exception_if_translation_does_not_exist(): void
420420
{
421+
$this->expectException(ModelNotFoundException::class);
422+
$this->expectExceptionMessage(sprintf('No query results for model [%s] %s', VegetableTranslation::class, 'xyz'));
423+
421424
$vegetable = Vegetable::create([
422425
'en' => ['name' => 'Peas'],
423426
]);
424427
static::assertEquals('en', $vegetable->translateOrFail('en')->locale);
425428

426-
$this->expectException(ModelNotFoundException::class);
427429
$vegetable->translateOrFail('xyz');
428430
}
429431

0 commit comments

Comments
 (0)