forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DatabasePostgresSchemaBuilderTest.php
executable file
·55 lines (48 loc) · 2.6 KB
/
DatabasePostgresSchemaBuilderTest.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
<?php
namespace Illuminate\Tests\Database;
use Illuminate\Database\Connection;
use Illuminate\Database\Query\Processors\PostgresProcessor;
use Illuminate\Database\Schema\Grammars\PostgresGrammar;
use Illuminate\Database\Schema\PostgresBuilder;
use Mockery as m;
use PHPUnit\Framework\TestCase;
class DatabasePostgresSchemaBuilderTest extends TestCase
{
protected function tearDown(): void
{
m::close();
}
public function testHasTable()
{
$connection = m::mock(Connection::class);
$grammar = m::mock(PostgresGrammar::class);
$connection->shouldReceive('getDatabaseName')->andReturn('db');
$connection->shouldReceive('getSchemaGrammar')->andReturn($grammar);
$connection->shouldReceive('getConfig')->with('database')->andReturn('db');
$connection->shouldReceive('getConfig')->with('schema')->andReturn('schema');
$connection->shouldReceive('getConfig')->with('search_path')->andReturn('public');
$builder = new PostgresBuilder($connection);
$grammar->shouldReceive('compileTableExists')->once()->andReturn('sql');
$connection->shouldReceive('getTablePrefix')->once()->andReturn('prefix_');
$connection->shouldReceive('selectFromWriteConnection')->once()->with('sql', ['db', 'public', 'prefix_table'])->andReturn(['prefix_table']);
$this->assertTrue($builder->hasTable('table'));
}
public function testGetColumnListing()
{
$connection = m::mock(Connection::class);
$grammar = m::mock(PostgresGrammar::class);
$processor = m::mock(PostgresProcessor::class);
$connection->shouldReceive('getDatabaseName')->andReturn('db');
$connection->shouldReceive('getSchemaGrammar')->andReturn($grammar);
$connection->shouldReceive('getPostProcessor')->andReturn($processor);
$connection->shouldReceive('getConfig')->with('database')->andReturn('db');
$connection->shouldReceive('getConfig')->with('schema')->andReturn('schema');
$connection->shouldReceive('getConfig')->with('search_path')->andReturn('public');
$grammar->shouldReceive('compileColumns')->with('db', 'public', 'prefix_table')->once()->andReturn('sql');
$processor->shouldReceive('processColumns')->once()->andReturn([['name' => 'column']]);
$builder = new PostgresBuilder($connection);
$connection->shouldReceive('getTablePrefix')->once()->andReturn('prefix_');
$connection->shouldReceive('selectFromWriteConnection')->once()->with('sql')->andReturn([['name' => 'column']]);
$this->assertEquals(['column'], $builder->getColumnListing('table'));
}
}