-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
258 additions
and
167 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Umbrellio\Postgres\Tests\Functional\Helpers; | ||
|
||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Facades\Schema; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @mixin TestCase | ||
*/ | ||
trait ColumnAssertions | ||
{ | ||
protected function assertCommentOnColumn(string $table, string $column, ?string $expected = null): void | ||
{ | ||
$comment = $this->getCommentListing($table, $column); | ||
|
||
if ($expected === null) { | ||
$this->assertNull($comment); | ||
} | ||
|
||
$this->assertSame($expected, $comment); | ||
} | ||
|
||
protected function assertDefaultOnColumn(string $table, string $column, ?string $expected = null): void | ||
{ | ||
$defaultValue = $this->getDefaultListing($table, $column); | ||
|
||
if ($expected === null) { | ||
$this->assertNull($defaultValue); | ||
} | ||
|
||
$this->assertSame($expected, $defaultValue); | ||
} | ||
|
||
protected function assertTypeColumn(string $table, string $column, string $expected): void | ||
{ | ||
$this->assertSame($expected, Schema::getColumnType($table, $column)); | ||
} | ||
private function getCommentListing(string $table, string $column) | ||
{ | ||
$definition = DB::selectOne( | ||
' | ||
SELECT pgd.description | ||
FROM pg_catalog.pg_statio_all_tables AS st | ||
INNER JOIN pg_catalog.pg_description pgd ON (pgd.objoid = st.relid) | ||
INNER JOIN information_schema.columns c ON pgd.objsubid = c.ordinal_position | ||
AND c.table_schema = st.schemaname AND c.table_name = st.relname | ||
WHERE c.table_name = ? AND c.column_name = ? | ||
', | ||
[$table, $column] | ||
); | ||
|
||
return $definition ? $definition->description : null; | ||
} | ||
|
||
private function getDefaultListing(string $table, string $column) | ||
{ | ||
$definition = DB::selectOne( | ||
' | ||
SELECT column_default | ||
FROM information_schema.columns c | ||
WHERE c.table_name = ? and c.column_name = ? | ||
', | ||
[$table, $column] | ||
); | ||
|
||
return $definition ? $definition->column_default : null; | ||
} | ||
} |
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,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Umbrellio\Postgres\Tests\Functional\Helpers; | ||
|
||
use Illuminate\Support\Facades\DB; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @mixin TestCase | ||
*/ | ||
trait IndexAssertions | ||
{ | ||
protected function seeIndex(string $index): void | ||
{ | ||
$this->assertNotNull($this->getIndexListing($index)); | ||
} | ||
|
||
protected function assertSameIndex(string $index, string $expectedDef): void | ||
{ | ||
$definition = $this->getIndexListing($index); | ||
|
||
$this->seeIndex($index); | ||
$this->assertSame($expectedDef, $definition); | ||
} | ||
|
||
protected function assertRegExpIndex(string $index, string $expectedDef): void | ||
{ | ||
$definition = $this->getIndexListing($index); | ||
|
||
$this->seeIndex($index); | ||
$this->assertRegExp($expectedDef, $definition); | ||
} | ||
private function getIndexListing($index): ?string | ||
{ | ||
$definition = DB::selectOne('SELECT indexdef FROM pg_indexes WHERE indexname = ?', [$index]); | ||
|
||
return $definition ? $definition->indexdef : null; | ||
} | ||
} |
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,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Umbrellio\Postgres\Tests\Functional\Helpers; | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @mixin TestCase | ||
*/ | ||
trait TableAssertions | ||
{ | ||
protected function assertCompareTables(string $sourceTable, string $destinationTable): void | ||
{ | ||
$this->assertSame($this->getTableDefinition($sourceTable), $this->getTableDefinition($destinationTable)); | ||
} | ||
|
||
protected function assertSameTable(array $expectedDef, string $table): void | ||
{ | ||
$definition = $this->getTableDefinition($table); | ||
|
||
$this->assertSame($expectedDef, $definition); | ||
} | ||
|
||
protected function seeTable(string $table): void | ||
{ | ||
$this->assertTrue(Schema::hasTable($table)); | ||
} | ||
|
||
private function getTableDefinition(string $table): array | ||
{ | ||
return Schema::getColumnListing($table); | ||
} | ||
} |
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
Oops, something went wrong.