Skip to content

Commit 716b069

Browse files
committed
test: add feature test for routing queries through configured database connection
1 parent dac035d commit 716b069

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Illuminate\Support\Facades\DB;
6+
use Illuminate\Support\Facades\Schema;
7+
use Pan\Contracts\AnalyticsRepository;
8+
use Pan\Enums\EventType;
9+
use Pan\PanConfiguration;
10+
11+
it('routes queries through the configured database connection', function (): void {
12+
config(['database.connections.secondary' => [
13+
'driver' => 'sqlite',
14+
'database' => ':memory:',
15+
'prefix' => '',
16+
]]);
17+
18+
Schema::connection('secondary')->create('pan_analytics', function ($table): void {
19+
$table->id();
20+
$table->string('name');
21+
$table->unsignedBigInteger('impressions')->default(0);
22+
$table->unsignedBigInteger('hovers')->default(0);
23+
$table->unsignedBigInteger('clicks')->default(0);
24+
});
25+
26+
PanConfiguration::databaseConnection('secondary');
27+
28+
app(AnalyticsRepository::class)->increment('help-modal', EventType::CLICK);
29+
30+
expect(DB::connection('secondary')->table('pan_analytics')->count())->toBe(1)
31+
->and(DB::table('pan_analytics')->count())->toBe(0);
32+
})->after(function (): void {
33+
DB::purge('secondary');
34+
PanConfiguration::databaseConnection(config('database.default'));
35+
});

0 commit comments

Comments
 (0)