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
|
<?php
namespace Illuminate\Tests\Database;
use Illuminate\Database\Connection;
use Illuminate\Database\Query\Processors\MySqlProcessor;
use Illuminate\Database\Schema\Grammars\MySqlGrammar;
use Illuminate\Database\Schema\MySqlBuilder;
use Mockery as m;
use PHPUnit\Framework\TestCase;
class DatabaseMySQLSchemaBuilderTest extends TestCase
{
protected function tearDown(): void
{
m::close();
}
public function testHasTable()
{
$connection = m::mock(Connection::class);
$grammar = m::mock(MySqlGrammar::class);
$processor = m::mock(MySqlProcessor::class);
$connection->shouldReceive('getDatabaseName')->andReturn('db');
$connection->shouldReceive('getSchemaGrammar')->andReturn($grammar);
$connection->shouldReceive('getPostProcessor')->andReturn($processor);
$builder = new MySqlBuilder($connection);
$grammar->shouldReceive('compileTables')->once()->andReturn('sql');
$processor->shouldReceive('processTables')->once()->andReturn([['name' => 'prefix_table']]);
$connection->shouldReceive('getTablePrefix')->once()->andReturn('prefix_');
$connection->shouldReceive('selectFromWriteConnection')->once()->with('sql')->andReturn([['name' => 'prefix_table']]);
$this->assertTrue($builder->hasTable('table'));
}
public function testGetColumnListing()
{
$connection = m::mock(Connection::class);
$grammar = m::mock(MySqlGrammar::class);
$processor = m::mock(MySqlProcessor::class);
$connection->shouldReceive('getDatabaseName')->andReturn('db');
$connection->shouldReceive('getSchemaGrammar')->andReturn($grammar);
$connection->shouldReceive('getPostProcessor')->andReturn($processor);
$grammar->shouldReceive('compileColumns')->with('db', 'prefix_table')->once()->andReturn('sql');
$processor->shouldReceive('processColumns')->once()->andReturn([['name' => 'column']]);
$builder = new MySqlBuilder($connection);
$connection->shouldReceive('getTablePrefix')->once()->andReturn('prefix_');
$connection->shouldReceive('selectFromWriteConnection')->once()->with('sql')->andReturn([['name' => 'column']]);
$this->assertEquals(['column'], $builder->getColumnListing('table'));
}
}
|