Testing with stancl/tenancy

I'm trying to test A resource page, and I'm getting the error in the screenshot, I'm using stancl/tenancy package and I have the tenancy initialization in the Base TestCase file, anyhelp?
<?php

namespace Tests\Feature\Filament\Resources;

use App\Filament\Resources\DomainResource;
use App\Filament\Resources\DomainResource\Pages\ListDomains;
use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Livewire\Livewire;
use App\Models\Domain;
use App\Models\Tenant;
use Tests\TestCase;

class DomainResourceTest extends TestCase
{
use DatabaseMigrations, RefreshDatabase, WithFaker;

public function setUp(): void
{
parent::setUp();

$user = User::factory()->create();
$user->permissions()->create(['name' => 'domains.viewAny']);
$this->actingAs($user);
}

public function test_render_page()
{
$this->get(DomainResource::getUrl('index'))->assertSuccessful();
}

public function test_list_domains()
{
$tenant = Tenant::factory()->create();
$domains = Domain::factory()->count(10)->create([
'tenant_id' => $tenant->id,
]);

Livewire::test(ListDomains::class)
->assertCanSeeTableRecords($domains);
}
}
<?php

namespace Tests\Feature\Filament\Resources;

use App\Filament\Resources\DomainResource;
use App\Filament\Resources\DomainResource\Pages\ListDomains;
use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Livewire\Livewire;
use App\Models\Domain;
use App\Models\Tenant;
use Tests\TestCase;

class DomainResourceTest extends TestCase
{
use DatabaseMigrations, RefreshDatabase, WithFaker;

public function setUp(): void
{
parent::setUp();

$user = User::factory()->create();
$user->permissions()->create(['name' => 'domains.viewAny']);
$this->actingAs($user);
}

public function test_render_page()
{
$this->get(DomainResource::getUrl('index'))->assertSuccessful();
}

public function test_list_domains()
{
$tenant = Tenant::factory()->create();
$domains = Domain::factory()->count(10)->create([
'tenant_id' => $tenant->id,
]);

Livewire::test(ListDomains::class)
->assertCanSeeTableRecords($domains);
}
}
14 Replies
Dan Harrin
Dan Harrinβ€’2y ago
clear your view cache?
YoussefMaged
YoussefMagedOPβ€’2y ago
@Dan Harrin I still got the same error I suspect it has something to do with wrong db/permissions configuration with stancl/tenancy Could it be the case?
Dan Harrin
Dan Harrinβ€’2y ago
i dont use that package so idk
YoussefMaged
YoussefMagedOPβ€’2y ago
Okay, thank you for the help a lot, really appreciate it πŸ™
LeandroFerreira
LeandroFerreiraβ€’2y ago
Is there the file here? storage/xxx what about the storage folder permission?
YoussefMaged
YoussefMagedOPβ€’2y ago
I actually fixed that from this link: https://tenancyforlaravel.com/docs/v3/realtime-facades/ but now I'm facing another error as the screenshot says Note: I'm using Laravel Sail locally
Tenancy for Laravel
Real-time facades | Tenancy for Laravel
Real-time facades | Tenancy for Laravel
YoussefMaged
YoussefMagedOPβ€’2y ago
I tried prefixing APP_URL with http:// but no success too
LeandroFerreira
LeandroFerreiraβ€’2y ago
the same method? test_list_domains() ?
LeandroFerreira
LeandroFerreiraβ€’2y ago
I have a multi tenant project with laravel sail as well https://github.com/leandrocfe/filament-multi-tenant tests are working for me
GitHub
GitHub - leandrocfe/filament-multi-tenant: A Filament multi tenant ...
A Filament multi tenant starter kit. Contribute to leandrocfe/filament-multi-tenant development by creating an account on GitHub.
YoussefMaged
YoussefMagedOPβ€’2y ago
Yes
LeandroFerreira
LeandroFerreiraβ€’2y ago
can you share the code on github? you can try https://github.com/leandrocfe/filament-multi-tenant if you want
GitHub
GitHub - leandrocfe/filament-multi-tenant: A Filament multi tenant ...
A Filament multi tenant starter kit. Contribute to leandrocfe/filament-multi-tenant development by creating an account on GitHub.
YoussefMaged
YoussefMagedOPβ€’2y ago
Hmm, I'll check it out and compare my .env and config/app.php to see what could be causing this error? Sure thing I have it on gitlab
LeandroFerreira
LeandroFerreiraβ€’2y ago
ok send me a DM πŸ‘
YoussefMaged
YoussefMagedOPβ€’2y ago
It's a private repo if you can give me your email so I can add you there
Want results from more Discord servers?
Add your server