forked from tursodatabase/libsql-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultiConnectionsTest.php
39 lines (30 loc) · 1.32 KB
/
MultiConnectionsTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Libsql\Laravel\Tests\Fixtures\Models\Project;
beforeEach(function () {
config()->set('database.connections.otherdb', [
'driver' => 'libsql',
'url' => "http://127.0.0.1:8080",
'password' => "your-access-token",
]);
migrateTables('projects');
$this->project1 = Project::factory()->create();
$this->project2 = Project::factory()->create();
$this->project3 = Project::factory()->create();
});
afterEach(function () {
Schema::dropAllTables();
});
test('each connection has its own turso client instance', function () {
$client1 = DB::connection('turso')->getPdo()->getClient();
$client2 = DB::connection('otherdb')->getPdo()->getClient();
expect($client1)->not->toBe($client2);
})->group('MultiConnectionsTest', 'FeatureTest');
test('it can get all rows from the projects table through the otherdb connection', function () {
$projects = DB::connection('otherdb')->table('projects')->get();
expect($projects)->toHaveCount(3)
->and($projects[0]->name)->toEqual($this->project1->name)
->and($projects[1]->name)->toEqual($this->project2->name)
->and($projects[2]->name)->toEqual($this->project3->name);
})->group('MultiConnectionsTest', 'FeatureTest');