Skip to content

Commit 7c358e2

Browse files
committed
- Add silent failing on tests if languages can't be loaded
1 parent 7fe91c4 commit 7c358e2

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

src/LanguageRegistrar.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Javaabu\Translatable;
44

5+
use Illuminate\Database\QueryException;
6+
use Illuminate\Support\Facades\Log;
57
use function array_key_exists;
68

79
use DateInterval;
@@ -91,9 +93,19 @@ public function getLanguages(array $params = []): Collection
9193
// Load up languages from cache
9294
if ($this->languages === null) {
9395
$this->languages = $this->cache->remember(self::$cache_key, self::$cache_expiration_time, function () {
94-
return $this->getLanguageClass()
95-
->active()
96-
->get();
96+
try {
97+
return $this->getLanguageClass()
98+
->active()
99+
->get();
100+
} catch (QueryException $e) {
101+
if (app()->runningUnitTests()) {
102+
// silently fail if languages can't be loaded in tests
103+
Log::error('LanguageRegistrarError: ' . $e->getMessage());
104+
return collect();
105+
}
106+
107+
throw $e;
108+
}
97109
});
98110
}
99111

0 commit comments

Comments
 (0)