forked from tursodatabase/libsql-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReadReplicaTest.php
56 lines (47 loc) · 1.85 KB
/
ReadReplicaTest.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
use Illuminate\Http\Client\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
beforeEach(function () {
$this->pdo = new \PDO('sqlite::memory:');
$this->pdo->exec('CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)');
$this->pdo->exec('INSERT INTO users (name) VALUES ("John Doe")');
$this->pdo->exec('INSERT INTO users (name) VALUES ("Jane Doe")');
DB::connection('turso')->setReadPdo($this->pdo);
});
test('it can retrieve data from read replica', function () {
$users = DB::table('users')->get();
expect($users)->toHaveCount(2)
->and($users[0]->name)->toBe('John Doe')
->and($users[1]->name)->toBe('Jane Doe');
})->group('ReadReplicaTest', 'FeatureTest');
test('it will use the primary database connection for data manipulation operation', function () {
fakeHttpRequest();
DB::table('users')->insert([
'name' => 'June Monroe',
]);
Http::assertSent(function (Request $request) {
expect($request->url())->toBe('http://127.0.0.1:8080/v3/pipeline')
->and($request->data())->toBe([
'requests' => [
[
'type' => 'execute',
'stmt' => [
'sql' => 'PRAGMA foreign_keys = ON;',
],
],
[
'type' => 'execute',
'stmt' => [
'sql' => 'insert into "users" ("name") values (?)',
'args' => [[
'type' => 'text',
'value' => 'June Monroe',
]],
],
],
],
]);
return true;
});
})->group('ReadReplicaTest', 'FeatureTest');