To initialize the app environment from the test, you can use the RefreshDatabase trait provided by Laravel. This trait will refresh the database before each test and also boot the application environment. Here's an example of how you can use it:
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class UtilitiesTest extends TestCase
{
use RefreshDatabase;
public function testOptionName()
{
$this->assertEquals('Zero', Utilities::optionName(0));
}
}
By using the RefreshDatabase trait, you can ensure that the app environment is loaded and the translation service is available from the service container.