forked from alexjustesen/speedtest-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVacuumDatabaseTest.php
More file actions
49 lines (39 loc) · 1.52 KB
/
VacuumDatabaseTest.php
File metadata and controls
49 lines (39 loc) · 1.52 KB
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
<?php
use App\Actions\VacuumDatabase;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
describe('VacuumDatabase', function () {
it('skips silently when the default connection is not sqlite', function () {
$connection = Mockery::mock();
$connection->shouldReceive('getDriverName')->andReturn('mysql');
$connection->shouldNotReceive('transactionLevel');
$connection->shouldNotReceive('statement');
DB::shouldReceive('connection')->andReturn($connection);
Log::spy();
VacuumDatabase::run();
Log::shouldNotHaveReceived('info');
Log::shouldNotHaveReceived('warning');
});
it('runs PRAGMA optimize and VACUUM on a sqlite connection', function () {
Config::set('database.connections.sqlite_vacuum_test', [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
'foreign_key_constraints' => true,
]);
Config::set('database.default', 'sqlite_vacuum_test');
DB::purge();
$statements = [];
DB::listen(function ($query) use (&$statements) {
$statements[] = $query->sql;
});
Log::spy();
VacuumDatabase::run();
expect($statements)->toContain('PRAGMA optimize;');
expect($statements)->toContain('VACUUM;');
Log::shouldHaveReceived('info')
->with('SQLite maintenance completed', Mockery::type('array'))
->once();
});
});