Skip to content

Commit

Permalink
Moving helpers for assertions to src (#24)
Browse files Browse the repository at this point in the history
* Added ColumnAssertions
* Added TableAssertions
* Added IndexAssertions
* Added ViewAssertions
  • Loading branch information
cugrif authored and pvsaintpe committed Aug 23, 2019
1 parent 3f8b253 commit 36197aa
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 23 deletions.
22 changes: 11 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ script:
fi
- |
if [ "x$COVERAGE" == "xyes" ]; then
./vendor/bin/phpunit --configuration phpunit.travis.xml --coverage-clover build/logs/clover.xml
./vendor/bin/phpunit --configuration phpunit.travis.xml --exclude-group $EXCLUDE_GROUP --coverage-clover build/logs/clover.xml
else
./vendor/bin/phpunit --configuration phpunit.travis.xml
./vendor/bin/phpunit --configuration phpunit.travis.xml --exclude-group $EXCLUDE_GROUP
fi
after_success:
Expand All @@ -46,48 +46,48 @@ matrix:
include:
- stage: Test
php: "7.2"
env: DB=pgsql POSTGRESQL_VERSION=11.0
env: DB=pgsql POSTGRESQL_VERSION=11.0 EXCLUDE_GROUP=WithSchema
sudo: required
services:
- docker
- stage: Test
php: "7.3"
env: DB=pgsql POSTGRESQL_VERSION=9.2 COVERAGE=yes
env: DB=pgsql POSTGRESQL_VERSION=9.2 COVERAGE=yes EXCLUDE_GROUP=WithSchema
services:
- postgresql
addons:
postgresql: "9.2"
- stage: Test
php: "7.3"
env: DB=pgsql POSTGRESQL_VERSION=9.3 COVERAGE=yes
env: DB=pgsql POSTGRESQL_VERSION=9.3 COVERAGE=yes EXCLUDE_GROUP=WithSchema
services:
- postgresql
addons:
postgresql: "9.3"
- stage: Test
php: "7.3"
env: DB=pgsql POSTGRESQL_VERSION=9.4 COVERAGE=yes
env: DB=pgsql POSTGRESQL_VERSION=9.4 COVERAGE=yes EXCLUDE_GROUP=WithSchema
services:
- postgresql
addons:
postgresql: "9.4"
- stage: Test
php: "7.3"
env: DB=pgsql POSTGRESQL_VERSION=9.5 COVERAGE=yes
env: DB=pgsql POSTGRESQL_VERSION=9.5 COVERAGE=yes EXCLUDE_GROUP=WithSchema
services:
- postgresql
addons:
postgresql: "9.5"
- stage: Test
php: "7.3"
env: DB=pgsql POSTGRESQL_VERSION=9.6 COVERAGE=yes
env: DB=pgsql POSTGRESQL_VERSION=9.6 COVERAGE=yes EXCLUDE_GROUP=WithSchema
services:
- postgresql
addons:
postgresql: "9.6"
- stage: Test
php: "7.3"
env: DB=pgsql POSTGRESQL_VERSION=10.0 COVERAGE=yes
env: DB=pgsql POSTGRESQL_VERSION=10.0 COVERAGE=yes EXCLUDE_GROUP=WithoutSchema
sudo: required
services:
- postgresql
Expand All @@ -97,7 +97,7 @@ matrix:
- bash ./tests/travis/install-postgres-10.sh
- stage: Test
php: "7.3"
env: DB=pgsql DOCKER_POSTGRES=yes POSTGRESQL_VERSION=11.0 COVERAGE=yes
env: DB=pgsql DOCKER_POSTGRES=yes POSTGRESQL_VERSION=11.0 COVERAGE=yes EXCLUDE_GROUP=WithoutSchema
sudo: required
services:
- docker
Expand All @@ -108,7 +108,7 @@ matrix:
- bash ./tests/travis/install-postgres-11.sh
- stage: Test
php: "7.4snapshot"
env: DB=pgsql DOCKER_POSTGRES=yes POSTGRESQL_VERSION=11.0
env: DB=pgsql DOCKER_POSTGRES=yes POSTGRESQL_VERSION=11.0 EXCLUDE_GROUP=WithoutSchema
sudo: required
services:
- docker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Umbrellio\Postgres\Tests\Functional\Helpers;
namespace Umbrellio\Postgres\Helpers;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Umbrellio\Postgres\Tests\Functional\Helpers;
namespace Umbrellio\Postgres\Helpers;

use Illuminate\Support\Facades\DB;
use PHPUnit\Framework\TestCase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Umbrellio\Postgres\Tests\Functional\Helpers;
namespace Umbrellio\Postgres\Helpers;

use Illuminate\Support\Facades\Schema;
use PHPUnit\Framework\TestCase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Umbrellio\Postgres\Tests\Functional\Helpers;
namespace Umbrellio\Postgres\Helpers;

use Illuminate\Support\Facades\Schema;
use PHPUnit\Framework\TestCase;
Expand Down
8 changes: 6 additions & 2 deletions tests.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env bash

psql postgres -U user -tc "SELECT 1 FROM pg_database WHERE datname = 'testing'" | grep -q 1 || psql postgres -U user -c "CREATE DATABASE testing"
psql postgres -U postgres -tc "SELECT 1 FROM pg_database WHERE datname = 'testing'" | grep -q 1 || psql postgres -U postgres -c "CREATE DATABASE testing"
composer lint
php -d pcov.directory='.' vendor/bin/phpunit --coverage-html build
if [ "x$EXCLUDE_GROUP" != "x" ]; then
php -d pcov.directory='.' vendor/bin/phpunit --exclude-group $EXCLUDE_GROUP --coverage-html build
else
php -d pcov.directory='.' vendor/bin/phpunit --coverage-html build
fi
52 changes: 50 additions & 2 deletions tests/Functional/Schema/CreateIndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Umbrellio\Postgres\Helpers\IndexAssertions;
use Umbrellio\Postgres\Helpers\TableAssertions;
use Umbrellio\Postgres\Schema\Blueprint;
use Umbrellio\Postgres\Tests\Functional\Helpers\IndexAssertions;
use Umbrellio\Postgres\Tests\Functional\Helpers\TableAssertions;
use Umbrellio\Postgres\Tests\FunctionalTestCase;

class CreateIndexTest extends FunctionalTestCase
Expand Down Expand Up @@ -43,6 +43,32 @@ public function createIndexIfNotExists(): void
$this->seeIndex('test_table_name_unique');
}

/**
* @test
* @group WithSchema
*/
public function createIndexWithSchema(): void
{
$this->createIndexDefinition();
$this->assertSameIndex(
'test_table_name_unique',
'CREATE UNIQUE INDEX test_table_name_unique ON public.test_table USING btree (name)'
);
}

/**
* @test
* @group WithoutSchema
*/
public function createIndexWithoutSchema(): void
{
$this->createIndexDefinition();
$this->assertSameIndex(
'test_table_name_unique',
'CREATE UNIQUE INDEX test_table_name_unique ON test_table USING btree (name)'
);
}

/**
* @test
* @dataProvider provideIndexes
Expand Down Expand Up @@ -253,6 +279,28 @@ protected function getDummyIndex(): string
return 'CREATE UNIQUE INDEX test_table_name_unique ON (public.)?test_table USING btree \(name\)';
}

private function createIndexDefinition(): void
{
Schema::create('test_table', function (Blueprint $table) {
$table->increments('id');
$table->string('name');

if (!$table->hasIndex(['name'], true)) {
$table->unique(['name']);
}
});

$this->seeTable('test_table');

Schema::table('test_table', function (Blueprint $table) {
if (!$table->hasIndex(['name'], true)) {
$table->unique(['name']);
}
});

$this->seeIndex('test_table_name_unique');
}

private function provideSuccessData(): Generator
{
yield [1, '2019-01-01', '2019-01-31'];
Expand Down
30 changes: 27 additions & 3 deletions tests/Functional/Schema/CreateTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,48 @@

use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Schema;
use Umbrellio\Postgres\Helpers\ColumnAssertions;
use Umbrellio\Postgres\Helpers\TableAssertions;
use Umbrellio\Postgres\Schema\Blueprint;
use Umbrellio\Postgres\Tests\Functional\Helpers\TableAssertions;
use Umbrellio\Postgres\Tests\FunctionalTestCase;

class CreateTableTest extends FunctionalTestCase
{
use DatabaseTransactions, TableAssertions;
use DatabaseTransactions, TableAssertions, ColumnAssertions;

/** @test */
public function createSimple(): void
{
Schema::create('test_table', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('field_comment')->comment('test');
$table->integer('field_default')->default(123);
});

$this->seeTable('test_table');
$this->assertSameTable(['id', 'name'], 'test_table');
}

/** @test */
public function columnAssertions(): void
{
Schema::create('test_table', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('field_comment')->comment('test');
$table->integer('field_default')->default(123);
});

$this->assertSameTable(['id', 'name', 'field_comment', 'field_default'], 'test_table');

$this->assertTypeColumn('test_table', 'id', 'integer');
$this->assertTypeColumn('test_table', 'name', 'string');

$this->assertDefaultOnColumn('test_table', 'field_default', '123');
$this->assertCommentOnColumn('test_table', 'field_comment', 'test');

$this->assertDefaultOnColumn('test_table', 'name');
$this->assertCommentOnColumn('test_table', 'name');
}

/** @test */
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/Schema/CreateViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Schema;
use Umbrellio\Postgres\Helpers\ViewAssertions;
use Umbrellio\Postgres\Schema\Blueprint;
use Umbrellio\Postgres\Tests\Functional\Helpers\ViewAssertions;
use Umbrellio\Postgres\Tests\FunctionalTestCase;

class CreateViewTest extends FunctionalTestCase
Expand Down

0 comments on commit 36197aa

Please sign in to comment.