Skip to content

Commit

Permalink
Fixed Scrutinizer issues & major bugs (#58)
Browse files Browse the repository at this point in the history
- Fixed major scrutinizer issues
- Updated readme
- Fixed issue with CI launch for other PR types
- Fixes for phpunit & composer
  • Loading branch information
pvsaintpe authored Jan 6, 2021
1 parent 14204b2 commit 6414e0c
Show file tree
Hide file tree
Showing 20 changed files with 145 additions and 97 deletions.
5 changes: 3 additions & 2 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ type:build:
- ".coveralls.yml"
- ".gitignore"
- "ecs.yml"
- "composer.json"
- "phpcs.xml"

dependencies:
- "composer.json"

type:helpers:
- "src/Helpers/**/*"

Expand Down Expand Up @@ -43,4 +45,3 @@ theme:docs:
- "CONTRIBUTING.md"
- "CODE_OF_CONDUCT.md"
- "src/.meta.php"
- "*.md"
14 changes: 0 additions & 14 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,10 @@ version-resolver:
major:
labels:
- major
- refactoring
minor:
labels:
- feature
- minor
- type:helpers
- type:indexes
- type:routines
- type:schema
- type:compilers
patch:
labels:
- patch
- type:build
- bug
- bugfix
- hotfix
- fix
- theme:docs
- analysis
default: patch
35 changes: 21 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ on:
- reopened
- edited
- synchronize
- labeled
- assigned
- unlabeled
- unlocked
- review_requested
- review_request_removed
- unassigned

env:
COVERAGE: '1'
Expand Down Expand Up @@ -71,53 +78,53 @@ jobs:
strategy:
fail-fast: false
matrix:
exclude_group:
- WithoutSchema,forPHP8
experimental:
- false
operating_system:
- ubuntu-latest
postgres:
- '10'
- '11'
- '12'
php_versions:
- '7.3'
- '7.4'
coverage: [false]
exclude_group: ['WithoutSchema,forPHP8']
experimental: [false]
operating_system: [ubuntu-latest]
postgres: ['10', '11', '12']
php_versions: ['7.3', '7.4']
include:
- operating_system: 'ubuntu-latest'
php_versions: '7.3'
postgres: '9.6'
experimental: false
coverage: true
exclude_group: WithoutSchema,forPHP8
- operating_system: 'ubuntu-latest'
php_versions: '7.3'
postgres: '13'
experimental: false
coverage: false
exclude_group: WithoutSchema,forPHP8
- operating_system: 'ubuntu-latest'
php_versions: '7.4'
postgres: '13'
experimental: false
coverage: false
exclude_group: WithoutSchema,forPHP8
- operating_system: 'ubuntu-latest'
php_versions: '8.0'
postgres: '10'
experimental: false
coverage: false
exclude_group: WithoutSchema,forPHP7
- operating_system: 'ubuntu-latest'
php_versions: '8.0'
postgres: '11'
experimental: false
coverage: false
exclude_group: WithoutSchema,forPHP7
- operating_system: 'ubuntu-latest'
php_versions: '8.0'
postgres: '12'
experimental: false
coverage: true
exclude_group: WithoutSchema,forPHP7
- operating_system: 'ubuntu-latest'
php_versions: '8.0'
postgres: '13'
coverage: false
experimental: false
exclude_group: WithoutSchema,forPHP7
runs-on: '${{ matrix.operating_system }}'
Expand Down Expand Up @@ -185,7 +192,7 @@ jobs:
--coverage-text
working-directory: './'
- name: Upload coverage results to Coveralls
if: ${{ !matrix.experimental }}
if: ${{ !matrix.experimental && matrix.coverage }}
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_PARALLEL: true
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
[![Code Coverage](https://scrutinizer-ci.com/g/umbrellio/laravel-pg-extensions/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/umbrellio/laravel-pg-extensions/?branch=master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/umbrellio/laravel-pg-extensions/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/umbrellio/laravel-pg-extensions/?branch=master)

This project extends Laravel`s database layer to allow use specific Postgres features without raw queries.
This project extends Laravel's database layer to allow use specific Postgres features without raw queries.

## Installation

Run this command to install:
```bash
php composer.phar require umbrellio/laravel-pg-extensions
composer require umbrellio/laravel-pg-extensions
```

## Features
Expand Down
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
"umbrellio/laravel-ltree": "Package for working with Postgres LTree extension",
"umbrellio/laravel-common-objects": "Package with helpers for common Laravel components"
},
"support": {
"issues": "https://github.com/umbrellio/laravel-pg-extensions/issues",
"source": "https://github.com/umbrellio/laravel-pg-extensions"
},
"require": {
"php": "^7.2|^7.3|^7.4|^8.0",
"doctrine/dbal": "2.9.*|^3.0",
Expand Down
16 changes: 8 additions & 8 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
<exclude>
<file>./src/.meta.php</file>
</exclude>
</coverage>
<php>
<env name="APP_ENV" value="testing"/>
<ini name="error_reporting" value="-1" />
Expand All @@ -19,14 +27,6 @@
<var name="db_database" value="${DATABASE}" />
<var name="db_port" value="5432"/>
</php>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
<exclude>
<file>./src/.meta.php</file>
</exclude>
</whitelist>
</filter>
<testsuites>
<testsuite name="Test suite">
<directory suffix="Test.php">./tests</directory>
Expand Down
23 changes: 22 additions & 1 deletion src/.meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\Database\Schema {

use Closure;
use Illuminate\Support\Fluent;
use Umbrellio\Postgres\Schema\Definitions\AttachPartitionDefinition;
use Umbrellio\Postgres\Schema\Definitions\CheckDefinition;
Expand All @@ -11,6 +12,8 @@
use Umbrellio\Postgres\Schema\Definitions\UniqueDefinition;

/**
* @method __construct($table, Closure $callback = null, $prefix = '')
*
* @method AttachPartitionDefinition attachPartition(string $partition)
* @method void detachPartition(string $partition)
* @method LikeDefinition like(string $table)
Expand All @@ -22,15 +25,33 @@
* @method ColumnDefinition tsrange(string $column)
* @method ExcludeDefinition exclude($columns, ?string $index = null)
* @method CheckDefinition check($columns, ?string $index = null)
* @method string getTable()
* @method ColumnDefinition|Fluent addColumn($type, $name, array $parameters = [])
*
* @property bool $temporary
*/
class Blueprint
{
protected function addCommand($name, array $parameters = []): Fluent
{
return new Fluent();
}

protected function createIndexName($type, array $columns): string
{
return '';
}

protected function dropIndexCommand($command, $type, $index): Fluent
{
return new Fluent();
}
}

/**
* @method ColumnDefinition using($expression)
*/
class ColumnDefinition
class ColumnDefinition extends Fluent
{
}
}
2 changes: 1 addition & 1 deletion src/Compilers/ExcludeCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private static function compileWheres(Grammar $grammar, Blueprint $blueprint, Fl
{
$wheres = static::build($grammar, $blueprint, $command);

if ($wheres) {
if (!empty($wheres)) {
return sprintf('WHERE %s', static::removeLeadingBoolean(implode(' ', $wheres)));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/UniqueCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static function compile(
'CREATE UNIQUE INDEX %s ON %s (%s) WHERE %s',
$fluent->get('index'),
$blueprint->getTable(),
implode(',', $fluent->get('columns')),
implode(',', (array) $fluent->get('columns')),
static::removeLeadingBoolean(implode(' ', $wheres))
);
}
Expand Down
7 changes: 3 additions & 4 deletions src/Helpers/ColumnAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use PHPUnit\Framework\TestCase;

/**
* @mixin TestCase
*/
trait ColumnAssertions
{
abstract public static function assertNull($actual, string $message = ''): void;
abstract public static function assertSame($expected, $actual, string $message = ''): void;

protected function assertCommentOnColumn(string $table, string $column, ?string $expected = null): void
{
$comment = $this->getCommentListing($table, $column);
Expand Down
24 changes: 15 additions & 9 deletions src/Helpers/IndexAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@
namespace Umbrellio\Postgres\Helpers;

use Illuminate\Support\Facades\DB;
use PHPUnit\Framework\TestCase;

/**
* @mixin TestCase
*/
trait IndexAssertions
{
abstract public static function assertNotNull($actual, string $message = ''): void;
abstract public static function assertSame($expected, $actual, string $message = ''): void;
abstract public static function assertNull($actual, string $message = ''): void;
abstract public static function assertMatchesRegularExpression(
string $pattern,
string $string,
string $message = ''
): void;
abstract public static function assertTrue($condition, string $message = ''): void;
abstract public static function assertFalse($condition, string $message = ''): void;

protected function seeIndex(string $index): void
{
$this->assertNotNull($this->getIndexListing($index));
Expand All @@ -35,7 +42,7 @@ protected function assertRegExpIndex(string $index, string $expectedDef): void
$definition = $this->getIndexListing($index);

$this->seeIndex($index);
$this->assertMatchesRegularExpression($expectedDef, $definition);
$this->assertMatchesRegularExpression($expectedDef, $definition ?: '');
}

protected function dontSeeConstraint(string $table, string $index): void
Expand All @@ -57,15 +64,14 @@ private function getIndexListing($index): ?string

private function existConstraintOnTable(string $table, string $index): bool
{
$definition = DB::selectOne('
$expression = '
SELECT c.conname
FROM pg_constraint c
LEFT JOIN pg_class t ON c.conrelid = t.oid
LEFT JOIN pg_class t2 ON c.confrelid = t2.oid
WHERE t.relname = ? AND c.conname = ?;
',
[$table, $index]
);
';
$definition = DB::selectOne($expression, [$table, $index]);
return $definition ? true : false;
}
}
7 changes: 3 additions & 4 deletions src/Helpers/TableAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
namespace Umbrellio\Postgres\Helpers;

use Illuminate\Support\Facades\Schema;
use PHPUnit\Framework\TestCase;

/**
* @mixin TestCase
*/
trait TableAssertions
{
abstract public static function assertSame($expected, $actual, string $message = ''): void;
abstract public static function assertTrue($condition, string $message = ''): void;

protected function assertCompareTables(string $sourceTable, string $destinationTable): void
{
$this->assertSame($this->getTableDefinition($sourceTable), $this->getTableDefinition($destinationTable));
Expand Down
8 changes: 4 additions & 4 deletions src/Helpers/ViewAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
namespace Umbrellio\Postgres\Helpers;

use Illuminate\Support\Facades\Schema;
use PHPUnit\Framework\TestCase;

/**
* @mixin TestCase
*/
trait ViewAssertions
{
abstract public static function assertSame($expected, $actual, string $message = ''): void;
abstract public static function assertTrue($condition, string $message = ''): void;
abstract public static function assertFalse($condition, string $message = ''): void;

protected function assertSameView(string $expectedDef, string $view): void
{
$definition = $this->getViewDefinition($view);
Expand Down
8 changes: 6 additions & 2 deletions src/PostgresConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class PostgresConnection extends BasePostgresConnection
{
use Macroable;

public $name;

private static $extensions = [];

private $initialTypes = [
Expand Down Expand Up @@ -135,7 +137,8 @@ private function registerExtensions(): void
/** @var AbstractExtension $extension */
$extension::register();
foreach ($extension::getTypes() as $type => $typeClass) {
$this->getSchemaBuilder()
$this
->getSchemaBuilder()
->registerCustomDoctrineType($typeClass, $type, $type);
}
});
Expand All @@ -147,7 +150,8 @@ private function overrideDoctrineBehavior(Connection $connection): Connection
if (!$eventManager->hasListeners(Events::onSchemaAlterTableChangeColumn)) {
$eventManager->addEventSubscriber(new SchemaAlterTableChangeColumnSubscriber());
}
$connection->getDatabasePlatform()
$connection
->getDatabasePlatform()
->setEventManager($eventManager);
return $connection;
}
Expand Down
Loading

0 comments on commit 6414e0c

Please sign in to comment.