-
I have a Laravel package that uses spatie/laravel-permission. I want to test my permissions. I copied the migration stub to the migrations folder of my package to create the tables. Laravel 10. In my tests, I want to run my seeder that inserts some roles and permissions into the tables. The service provider of my package registers the migrations like so: public function register() : void
{
$this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
} My test case looks like this: class PermissionsTest extends TestCase
{
use RefreshDatabase;
/** @testdox .... */
public function test_some_permission() : void
{
$this->seed(RolesAndPermissionsSeeder::class);
// ... assertions
}
/**
* Prepare the testing environment.
*
* @param \Illuminate\Foundation\Application $app
* @return void
*/
protected function getEnvironmentSetUp($app) : void
{
$app['config']->set('database.default', 'testing');
$app['config']->set('database.connections.testing', [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
]);
}
/**
* The migrations to load prior to testing.
*
* @return void
*/
protected function defineDatabaseMigrations() : void
{
$this->loadLaravelMigrations();
}
} This test does not run. As soon as I comment out the loadMigrationsFrom method, the error dissapears. I think it might be because the migration uses Any tips as to where to start debugging this, or any fix? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Laravel version? package version? php version? |
Beta Was this translation helpful? Give feedback.
-
It is because the config is not present because it is a package. I can do this in my test case OR service provider and it fixes it:
This works, but it is really hacky. Anyone with a better solution? |
Beta Was this translation helpful? Give feedback.
-
Did you try adding /**
* @param \Illuminate\Foundation\Application $app
* @return array
*/
protected function getPackageProviders($app)
{
return [
\Spatie\Permission\PermissionServiceProvider::class,
];
} |
Beta Was this translation helpful? Give feedback.
Did you try adding