/
DatabaseSqliteSchemaStateTest.php
58 lines (47 loc) · 2.39 KB
/
DatabaseSqliteSchemaStateTest.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
57
58
<?php
namespace Illuminate\Tests\Database;
use Illuminate\Database\Schema\SqliteSchemaState;
use Illuminate\Database\SQLiteConnection;
use Illuminate\Filesystem\Filesystem;
use Mockery as m;
use PDO;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\Process;
class DatabaseSqliteSchemaStateTest extends TestCase
{
protected function tearDown(): void
{
parent::tearDown();
m::close();
}
public function testLoadSchemaToDatabase(): void
{
$config = ['driver' => 'sqlite', 'database' => 'database/database.sqlite', 'prefix' => '', 'foreign_key_constraints' => true, 'name' => 'sqlite'];
$connection = m::mock(SQLiteConnection::class);
$connection->shouldReceive('getConfig')->andReturn($config);
$connection->shouldReceive('getDatabaseName')->andReturn($config['database']);
$process = m::spy(Process::class);
$processFactory = function () use ($process) {
return $process;
};
$schemaState = new SqliteSchemaState($connection, null, $processFactory);
$schemaState->load('database/schema/sqlite-schema.dump');
$process->shouldHaveReceived('mustRun')->with(null, [
'LARAVEL_LOAD_DATABASE' => 'database/database.sqlite',
'LARAVEL_LOAD_PATH' => 'database/schema/sqlite-schema.dump',
]);
}
public function testLoadSchemaToInMemory(): void
{
$config = ['driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '', 'foreign_key_constraints' => true, 'name' => 'sqlite'];
$connection = m::mock(SQLiteConnection::class);
$connection->shouldReceive('getConfig')->andReturn($config);
$connection->shouldReceive('getDatabaseName')->andReturn($config['database']);
$connection->shouldReceive('getPdo')->andReturn($pdo = m::spy(PDO::class));
$files = m::mock(Filesystem::class);
$files->shouldReceive('get')->andReturn('CREATE TABLE IF NOT EXISTS "migrations" ("id" integer not null primary key autoincrement, "migration" varchar not null, "batch" integer not null);');
$schemaState = new SqliteSchemaState($connection, $files);
$schemaState->load('database/schema/sqlite-schema.dump');
$pdo->shouldHaveReceived('exec')->with('CREATE TABLE IF NOT EXISTS "migrations" ("id" integer not null primary key autoincrement, "migration" varchar not null, "batch" integer not null);');
}
}