mercredi 2 janvier 2019

Use User model in a Lumen package

I wrote a Lumen package that make a reference to User Model.

I can't use Illuminate\Foundation\Auth\User because it doesn't exists with Lumen 5.7

I've made a config file that I publish, which give a reference to the User model that exists in the app. In this case:

my-config-plugin.php

'user' => [
        'table'       => 'users',
        'primary_key' => 'id',
        'foreign_key' => 'user_id',
        'model'       => App\User::class,
    ],

so, in all my package, I use:

config('my-config-plugin.user.model') and it resolves to App\User::class

But my problem comes with my tests, because there is no App\User::class defined in my package, so all the tests fail.

So, the only solution I find is to define my tests in another Lumen project that will have a User model and will install the plugin, but I don't like very much to ave my tests in another repository. Am I missing the good way to do it?

Aucun commentaire:

Enregistrer un commentaire