Skip to content

Commit

Permalink
make exception more precise
Browse files Browse the repository at this point in the history
  • Loading branch information
Gummibeer committed Jan 28, 2020
1 parent 5203dbf commit 1ef559c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Translatable/Translatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public function getTranslationOrNew(?string $locale = null): Model
public function getTranslationOrFail(string $locale): Model
{
if (($translation = $this->getTranslation($locale, false)) === null) {
throw new ModelNotFoundException();
throw (new ModelNotFoundException)->setModel($this->getTranslationModelName(), $locale);
}

return $translation;
Expand Down
4 changes: 3 additions & 1 deletion tests/TranslatableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,12 +418,14 @@ public function it_has_methods_that_return_always_a_translation(): void
/** @test */
public function it_throws_an_exception_if_translation_does_not_exist(): void
{
$this->expectException(ModelNotFoundException::class);
$this->expectExceptionMessage(sprintf('No query results for model [%s] %s', VegetableTranslation::class, 'xyz'));

$vegetable = Vegetable::create([
'en' => ['name' => 'Peas'],
]);
static::assertEquals('en', $vegetable->translateOrFail('en')->locale);

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

Expand Down

0 comments on commit 1ef559c

Please sign in to comment.