File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
tests/Feature/Laravel/Repositories Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 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+ });
You can’t perform that action at this time.
0 commit comments