-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support gist/gin indexes
- Loading branch information
Showing
8 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Umbrellio\Postgres\Tests\Unit\Schema\Grammars; | ||
|
||
use Mockery; | ||
use Umbrellio\Postgres\PostgresConnection; | ||
use Umbrellio\Postgres\Schema\Blueprint; | ||
use Umbrellio\Postgres\Schema\Grammars\PostgresGrammar; | ||
use Umbrellio\Postgres\Tests\TestCase; | ||
|
||
class GrammarTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function addingGinIndex() | ||
{ | ||
$blueprint = new Blueprint('test'); | ||
$blueprint->gin('foo'); | ||
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); | ||
$this->assertCount(1, $statements); | ||
$this->assertStringContainsString('CREATE INDEX', $statements[0]); | ||
$this->assertStringContainsString('GIN("foo")', $statements[0]); | ||
} | ||
|
||
/** @test */ | ||
public function addingGistIndex() | ||
{ | ||
$blueprint = new Blueprint('test'); | ||
$blueprint->gist('foo'); | ||
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); | ||
$this->assertCount(1, $statements); | ||
$this->assertStringContainsString('CREATE INDEX', $statements[0]); | ||
$this->assertStringContainsString('GIST("foo")', $statements[0]); | ||
} | ||
|
||
/** | ||
* @return PostgresConnection | ||
*/ | ||
protected function getConnection() | ||
{ | ||
return Mockery::mock(PostgresConnection::class); | ||
} | ||
|
||
protected function getGrammar() | ||
{ | ||
return new PostgresGrammar(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Umbrellio\Postgres\Unit\Schema; | ||
|
||
use Mockery; | ||
use Umbrellio\Postgres\Schema\Blueprint; | ||
use Umbrellio\Postgres\Tests\TestCase; | ||
|
||
class IndexTest extends TestCase | ||
{ | ||
/** @var Mockery\Mock */ | ||
protected $blueprint; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->blueprint = Mockery::mock(Blueprint::class) | ||
->makePartial() | ||
->shouldAllowMockingProtectedMethods(); | ||
} | ||
|
||
/** @test */ | ||
public function ginIndex() | ||
{ | ||
$this->blueprint | ||
->shouldReceive('indexCommand') | ||
->with('gin', 'col', 'myName'); | ||
$this->blueprint->gin('col', 'myName'); | ||
} | ||
|
||
/** @test */ | ||
public function gistIndex() | ||
{ | ||
$this->blueprint | ||
->shouldReceive('indexCommand') | ||
->with('gist', 'col', 'myName'); | ||
$this->blueprint->gist('col', 'myName'); | ||
} | ||
} |