diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 5fd8d89..ef477e9 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -20,10 +20,10 @@ on:
env:
COVERAGE: '1'
- php_extensions: 'apcu, bcmath, ctype, curl, dom, iconv, intl, json, mbstring, opcache, openssl, pdo, pdo_pgsql, pcntl, pcov, posix, redis, session, simplexml, sockets, tokenizer, xml, xmlwriter, zip'
+ php_extensions: 'apcu, bcmath, ctype, curl, dom, iconv, intl, json, mbstring, opcache, openssl, pdo, pdo_pgsql, pcntl, pcov, posix, redis, session, simplexml, sockets, tokenizer, xml, xmlwriter, zip, xdebug'
key: cache-v0.1
DB_USER: 'postgres'
- DB_NAME: 'testing'
+ DB_NAME: 'postgres'
DB_PASSWORD: 'postgres'
DB_HOST: '127.0.0.1'
@@ -36,7 +36,7 @@ jobs:
operating_system:
- ubuntu-latest
php_versions:
- - '7.4'
+ - '8.3'
fail-fast: false
env:
PHP_CS_FIXER_FUTURE_MODE: '0'
@@ -78,67 +78,22 @@ jobs:
strategy:
fail-fast: false
matrix:
- coverage: [false]
- exclude_group: ['WithoutSchema,forPHP8']
+ coverage: [true]
experimental: [false]
operating_system: [ubuntu-latest]
- postgres: ['10', '11', '12']
- php_versions: ['7.3', '7.4']
+ postgres: ['10', '11', '12', '13', '14']
+ php_versions: ['8.3']
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
- - operating_system: 'ubuntu-latest'
- php_versions: '8.1'
- postgres: '14'
+ php_versions: '8.3'
+ postgres: '15'
coverage: false
- experimental: false
- exclude_group: WithoutSchema,forPHP7
+ experimental: true
- operating_system: 'ubuntu-latest'
- php_versions: '8.2'
- postgres: '15'
+ php_versions: '8.4'
+ postgres: '16'
coverage: false
- experimental: false
- exclude_group: WithoutSchema,forPHP7
+ experimental: true
runs-on: '${{ matrix.operating_system }}'
services:
postgres:
@@ -181,8 +136,8 @@ jobs:
with:
php-version: ${{ matrix.php_versions }}
extensions: ${{ env.php_extensions }}
- ini-values: 'pcov.directory=src, date.timezone=UTC, upload_max_filesize=20M, post_max_size=20M, memory_limit=512M, short_open_tag=Off'
- coverage: pcov
+ ini-values: 'date.timezone=UTC, upload_max_filesize=20M, post_max_size=20M, memory_limit=512M, short_open_tag=Off, xdebug.mode="develop,coverage"'
+ coverage: xdebug
tools: 'phpunit'
- name: 'Install PHP dependencies with Composer'
continue-on-error: ${{ matrix.experimental }}
@@ -191,6 +146,7 @@ jobs:
- name: 'Run Unit Tests with PHPUnit'
continue-on-error: ${{ matrix.experimental }}
run: |
+ php -v
sed -e "s/\${USERNAME}/${{ env.DB_USER }}/" \
-e "s/\${PASSWORD}/${{ env.DB_PASSWORD }}/" \
-e "s/\${DATABASE}/${{ env.DB_NAME }}/" \
@@ -198,9 +154,9 @@ jobs:
phpunit.xml.dist > phpunit.xml
./vendor/bin/phpunit \
--stderr \
- --exclude-group ${{ matrix.exclude_group }} \
--coverage-clover build/logs/clover.xml \
--coverage-text
+ cat build/logs/clover.xml
working-directory: './'
- name: Upload coverage results to Coveralls
if: ${{ !matrix.experimental && matrix.coverage }}
diff --git a/.gitignore b/.gitignore
index 68c920a..6a8d4eb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,5 +3,6 @@
.ecs_cache
phpunit.xml
.phpunit.result.cache
-/build
+.phpunit.cache
composer.lock
+/build
diff --git a/.run/Functional.run.xml b/.run/Functional.run.xml
new file mode 100644
index 0000000..567a2ad
--- /dev/null
+++ b/.run/Functional.run.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.run/Tests .run.xml b/.run/Tests .run.xml
new file mode 100644
index 0000000..5d322b5
--- /dev/null
+++ b/.run/Tests .run.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.run/Unit.run.xml b/.run/Unit.run.xml
new file mode 100644
index 0000000..2a94904
--- /dev/null
+++ b/.run/Unit.run.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/build/logs/clover.xml b/build/logs/clover.xml
new file mode 100644
index 0000000..0f79eb6
--- /dev/null
+++ b/build/logs/clover.xml
@@ -0,0 +1,843 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/composer.json b/composer.json
index 9c901b3..ffddd26 100644
--- a/composer.json
+++ b/composer.json
@@ -34,16 +34,16 @@
},
"require": {
"ext-pdo": "*",
- "php": "^7.2|^7.3|^7.4|^8.0|^8.1|^8.2",
- "doctrine/dbal": "^2.9|^3.0",
- "laravel/framework": "^5.8|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0"
+ "php": "^8.3|^8.4",
+ "doctrine/dbal": "3.6.*",
+ "laravel/framework": "^11.0"
},
"require-dev": {
"umbrellio/code-style-php": "^1.0",
- "orchestra/testbench": "^3.5|^6.0|^4.0|^7.0|^8.0|^9.0",
- "php-coveralls/php-coveralls": "^2.1|^2.7",
- "codeception/codeception": "^3.0|^4.0|^5.0",
- "phpunit/phpunit": "^9.6|^10.0|^11.0"
+ "orchestra/testbench": "^9.0",
+ "php-coveralls/php-coveralls": "^2.7",
+ "codeception/codeception": "^5.0",
+ "phpunit/phpunit": "^11.0"
},
"scripts": {
"lint": [
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 392c602..171e95d 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,30 +1,18 @@
-
-
-
- ./src
-
-
- ./src/.meta.php
-
+
+
+
+
+
-
+
-
-
-
-
+
+
+
+
@@ -32,4 +20,12 @@
./tests
+
+
+ ./src
+
+
+ ./src/.meta.php
+
+
diff --git a/src/Compilers/CreateCompiler.php b/src/Compilers/CreateCompiler.php
index 494c770..1e6c3dc 100644
--- a/src/Compilers/CreateCompiler.php
+++ b/src/Compilers/CreateCompiler.php
@@ -30,6 +30,9 @@ private static function beforeTable(?Fluent $command = null): string
return $command ? 'if not exists' : '';
}
+ /**
+ * @codeCoverageIgnore
+ */
private static function compileLike(Grammar $grammar, Fluent $command): string
{
$table = $command->get('table');
diff --git a/src/PostgresConnection.php b/src/PostgresConnection.php
index 218f038..a0c5ba1 100644
--- a/src/PostgresConnection.php
+++ b/src/PostgresConnection.php
@@ -5,17 +5,14 @@
namespace Umbrellio\Postgres;
use DateTimeInterface;
-use Doctrine\DBAL\Connection;
-use Doctrine\DBAL\Events;
+use Doctrine\DBAL\Types\Type;
use Illuminate\Database\PostgresConnection as BasePostgresConnection;
-use Illuminate\Support\Facades\DB;
use Illuminate\Support\Traits\Macroable;
use PDO;
use Umbrellio\Postgres\Extensions\AbstractExtension;
use Umbrellio\Postgres\Extensions\Exceptions\ExtensionInvalidException;
use Umbrellio\Postgres\Schema\Builder;
use Umbrellio\Postgres\Schema\Grammars\PostgresGrammar;
-use Umbrellio\Postgres\Schema\Subscribers\SchemaAlterTableChangeColumnSubscriber;
use Umbrellio\Postgres\Schema\Types\NumericType;
use Umbrellio\Postgres\Schema\Types\TsRangeType;
use Umbrellio\Postgres\Schema\Types\TsTzRangeType;
@@ -66,13 +63,6 @@ public function useDefaultPostProcessor(): void
$this->registerInitialTypes();
}
- public function getDoctrineConnection(): Connection
- {
- $doctrineConnection = parent::getDoctrineConnection();
- $this->overrideDoctrineBehavior($doctrineConnection);
- return $doctrineConnection;
- }
-
public function bindValues($statement, $bindings)
{
if ($this->getPdo()->getAttribute(PDO::ATTR_EMULATE_PREPARES)) {
@@ -124,7 +114,9 @@ protected function getDefaultSchemaGrammar()
private function registerInitialTypes(): void
{
foreach ($this->initialTypes as $type => $typeClass) {
- DB::registerDoctrineType($typeClass, $type, $type);
+ if (! Type::hasType($type)) {
+ Type::addType($type, $typeClass);
+ }
}
}
@@ -137,20 +129,10 @@ private function registerExtensions(): void
/** @var AbstractExtension $extension */
$extension::register();
foreach ($extension::getTypes() as $type => $typeClass) {
- DB::registerDoctrineType($typeClass, $type, $type);
+ if (! Type::hasType($type)) {
+ Type::addType($type, $typeClass);
+ }
}
});
}
-
- private function overrideDoctrineBehavior(Connection $connection): Connection
- {
- $eventManager = $connection->getEventManager();
- if (! $eventManager->hasListeners(Events::onSchemaAlterTableChangeColumn)) {
- $eventManager->addEventSubscriber(new SchemaAlterTableChangeColumnSubscriber());
- }
- $connection
- ->getDatabasePlatform()
- ->setEventManager($eventManager);
- return $connection;
- }
}
diff --git a/src/Schema/Blueprint.php b/src/Schema/Blueprint.php
index 37d4a38..2fc5a88 100644
--- a/src/Schema/Blueprint.php
+++ b/src/Schema/Blueprint.php
@@ -4,6 +4,7 @@
namespace Umbrellio\Postgres\Schema;
+use Doctrine\DBAL\DriverManager;
use Illuminate\Database\Schema\Blueprint as BaseBlueprint;
use Illuminate\Database\Schema\ColumnDefinition;
use Illuminate\Support\Facades\Schema;
@@ -167,7 +168,9 @@ public function daterange(string $column): Fluent
protected function getSchemaManager()
{
- return Schema::getConnection()->getDoctrineSchemaManager();
+ $connection = Schema::getConnection();
+ $doctrineConnection = DriverManager::getConnection($connection->getConfig());
+ return $doctrineConnection->getSchemaManager();
}
private function addExtendedCommand(string $fluent, string $name, array $parameters = []): Fluent
diff --git a/src/Schema/Builder.php b/src/Schema/Builder.php
index fbc25c5..487e636 100644
--- a/src/Schema/Builder.php
+++ b/src/Schema/Builder.php
@@ -14,6 +14,9 @@ class Builder extends BasePostgresBuilder
public $name;
+ /**
+ * @codeCoverageIgnore
+ */
public function createView(string $view, string $select, $materialize = false): void
{
$blueprint = $this->createBlueprint($view);
@@ -21,6 +24,9 @@ public function createView(string $view, string $select, $materialize = false):
$this->build($blueprint);
}
+ /**
+ * @codeCoverageIgnore
+ */
public function dropView(string $view): void
{
$blueprint = $this->createBlueprint($view);
@@ -28,6 +34,9 @@ public function dropView(string $view): void
$this->build($blueprint);
}
+ /**
+ * @codeCoverageIgnore
+ */
public function hasView($view): bool
{
return count($this->connection->selectFromWriteConnection($this->grammar->compileViewExists(), [
@@ -36,11 +45,17 @@ public function hasView($view): bool
])) > 0;
}
+ /**
+ * @codeCoverageIgnore
+ */
public function getForeignKeys($tableName): array
{
return $this->connection->selectFromWriteConnection($this->grammar->compileForeignKeysListing($tableName));
}
+ /**
+ * @codeCoverageIgnore
+ */
public function getViewDefinition($view): string
{
$results = $this->connection->selectFromWriteConnection($this->grammar->compileViewDefinition(), [
diff --git a/src/Schema/Grammars/PostgresGrammar.php b/src/Schema/Grammars/PostgresGrammar.php
index 9bacf67..a4a582e 100644
--- a/src/Schema/Grammars/PostgresGrammar.php
+++ b/src/Schema/Grammars/PostgresGrammar.php
@@ -36,11 +36,17 @@ public function compileCreate(Blueprint $blueprint, Fluent $command): string
);
}
+ /**
+ * @codeCoverageIgnore
+ */
public function compileAttachPartition(Blueprint $blueprint, Fluent $command): string
{
return AttachPartitionCompiler::compile($this, $blueprint, $command);
}
+ /**
+ * @codeCoverageIgnore
+ */
public function compileDetachPartition(Blueprint $blueprint, Fluent $command): string
{
return sprintf(
@@ -50,7 +56,10 @@ public function compileDetachPartition(Blueprint $blueprint, Fluent $command): s
);
}
- public function compileCreateView(/** @scrutinizer ignore-unused */ Blueprint $blueprint, Fluent $command): string
+ /**
+ * @codeCoverageIgnore
+ */
+ public function compileCreateView(Blueprint $blueprint, Fluent $command): string
{
$materialize = $command->get('materialize') ? 'materialized' : '';
return implode(' ', array_filter([
@@ -63,16 +72,25 @@ public function compileCreateView(/** @scrutinizer ignore-unused */ Blueprint $b
]));
}
- public function compileDropView(/** @scrutinizer ignore-unused */ Blueprint $blueprint, Fluent $command): string
+ /**
+ * @codeCoverageIgnore
+ */
+ public function compileDropView(Blueprint $blueprint, Fluent $command): string
{
return 'drop view ' . $this->wrapTable($command->get('view'));
}
+ /**
+ * @codeCoverageIgnore
+ */
public function compileViewExists(): string
{
return 'select * from information_schema.views where table_schema = ? and table_name = ?';
}
+ /**
+ * @codeCoverageIgnore
+ */
public function compileForeignKeysListing(string $tableName): string
{
return sprintf("
@@ -92,6 +110,9 @@ public function compileForeignKeysListing(string $tableName): string
", $tableName);
}
+ /**
+ * @codeCoverageIgnore
+ */
public function compileViewDefinition(): string
{
return 'select view_definition from information_schema.views where table_schema = ? and table_name = ?';
@@ -133,17 +154,17 @@ protected function typeNumeric(Fluent $column): string
return $type;
}
- protected function typeTsrange(/** @scrutinizer ignore-unused */ Fluent $column): string
+ protected function typeTsrange(Fluent $column): string
{
return TsRangeType::TYPE_NAME;
}
- protected function typeTstzrange(/** @scrutinizer ignore-unused */ Fluent $column): string
+ protected function typeTstzrange(Fluent $column): string
{
return TsTzRangeType::TYPE_NAME;
}
- protected function typeDaterange(/** @scrutinizer ignore-unused */ Fluent $column): string
+ protected function typeDaterange(Fluent $column): string
{
return DateRangeType::TYPE_NAME;
}
diff --git a/src/Schema/Subscribers/SchemaAlterTableChangeColumnSubscriber.php b/src/Schema/Subscribers/SchemaAlterTableChangeColumnSubscriber.php
deleted file mode 100644
index 9409809..0000000
--- a/src/Schema/Subscribers/SchemaAlterTableChangeColumnSubscriber.php
+++ /dev/null
@@ -1,242 +0,0 @@
-preventDefault();
-
- $sql = $this->getAlterTableChangeColumnSQL(
- $event->getPlatform(),
- $event->getTableDiff(),
- $event->getColumnDiff()
- );
-
- $event->addSql($sql->unique()->toArray());
- }
-
- public function getSubscribedEvents(): array
- {
- return [Events::onSchemaAlterTableChangeColumn];
- }
-
- public function getAlterTableChangeColumnSQL(
- AbstractPlatform $platform,
- TableDiff $diff,
- ColumnDiff $columnDiff
- ): Collection {
- $sql = new Collection();
-
- $quoteName = $this->quoteName($platform, $diff);
-
- $oldColumnName = $columnDiff
- ->getOldColumnName()
- ->getQuotedName($platform);
- $column = $columnDiff->column;
-
- $this->compileAlterColumnType($platform, $columnDiff, $column, $quoteName, $oldColumnName, $sql);
-
- $this->compileAlterColumnDefault($platform, $columnDiff, $column, $quoteName, $oldColumnName, $sql);
-
- $this->compileAlterColumnNull($columnDiff, $column, $quoteName, $oldColumnName, $sql);
-
- $this->compileAlterColumnSequence($platform, $columnDiff, $diff, $column, $quoteName, $oldColumnName, $sql);
-
- $this->compileAlterColumnComment($platform, $columnDiff, $column, $quoteName, $sql);
-
- if (! $columnDiff->hasChanged('length')) {
- return $sql;
- }
-
- $sql->add(sprintf(
- 'ALTER TABLE %s ALTER %s TYPE %s',
- $quoteName,
- $oldColumnName,
- $column
- ->getType()
- ->getSQLDeclaration($column->toArray(), $platform)
- ));
-
- return $sql;
- }
-
- public function compileAlterColumnComment(
- AbstractPlatform $platform,
- ColumnDiff $columnDiff,
- Column $column,
- string $quoteName,
- Collection $sql
- ): void {
- $newComment = $this->getColumnComment($column);
- $oldComment = $this->getOldColumnComment($columnDiff);
-
- if (($columnDiff->fromColumn !== null && $oldComment !== $newComment)
- || $columnDiff->hasChanged('comment')
- ) {
- $sql->add($platform->getCommentOnColumnSQL($quoteName, $column->getQuotedName($platform), $newComment));
- }
- }
-
- public function compileAlterColumnNull(
- ColumnDiff $columnDiff,
- Column $column,
- string $quoteName,
- string $oldColumnName,
- Collection $sql
- ): void {
- if ($columnDiff->hasChanged('notnull')) {
- $sql->add(sprintf(
- 'ALTER TABLE %s ALTER %s %s NOT NULL',
- $quoteName,
- $oldColumnName,
- ($column->getNotnull() ? 'SET' : 'DROP')
- ));
- }
- }
-
- public function compileAlterColumnDefault(
- AbstractPlatform $platform,
- ColumnDiff $columnDiff,
- Column $column,
- string $quoteName,
- string $oldColumnName,
- Collection $sql
- ): void {
- if ($columnDiff->hasChanged('default') || $this->typeChangeBreaksDefaultValue($columnDiff)) {
- $defaultClause = $column->getDefault() === null
- ? ' DROP DEFAULT'
- : ' SET' . $this->getDefaultValueDeclarationSQL($platform, $column);
- $sql->add(sprintf('ALTER TABLE %s ALTER %s %s', $quoteName, $oldColumnName, trim($defaultClause)));
- }
- }
-
- public function compileAlterColumnSequence(
- AbstractPlatform $platform,
- ColumnDiff $columnDiff,
- TableDiff $diff,
- Column $column,
- string $quoteName,
- string $oldColumnName,
- Collection $sql
- ): void {
- if (! $columnDiff->hasChanged('autoincrement')) {
- return;
- }
-
- if (! $column->getAutoincrement()) {
- $sql->add(sprintf('ALTER TABLE %s ALTER %s DROP DEFAULT', $quoteName, $oldColumnName));
- return;
- }
-
- $seqName = $platform->getIdentitySequenceName($diff->name, $oldColumnName);
-
- $sql->add(sprintf('CREATE SEQUENCE %s', $seqName));
- $sql->add(sprintf("SELECT setval('%s', (SELECT MAX(%s) FROM %s))", $seqName, $oldColumnName, $quoteName));
- $sql->add(sprintf("ALTER TABLE %s ALTER %s SET DEFAULT nextval('%s')", $quoteName, $oldColumnName, $seqName));
- }
-
- public function compileAlterColumnType(
- AbstractPlatform $platform,
- ColumnDiff $columnDiff,
- Column $column,
- string $quoteName,
- string $oldColumnName,
- Collection $sql
- ): void {
- if (! $columnDiff->hasChanged('type')
- && ! $columnDiff->hasChanged('precision')
- && ! $columnDiff->hasChanged('scale')
- && ! $columnDiff->hasChanged('fixed')
- ) {
- return;
- }
-
- $type = $column->getType();
-
- $columnDefinition = $column->toArray();
- $columnDefinition['autoincrement'] = false;
-
- if ($this->typeChangeBreaksDefaultValue($columnDiff)) {
- $sql->add(sprintf('ALTER TABLE %s ALTER %s DROP DEFAULT', $quoteName, $oldColumnName));
- }
-
- $typeName = $type->getSQLDeclaration($columnDefinition, $platform);
-
- if ($columnDiff->hasChanged('type')) {
- $using = sprintf('USING %s::%s', $oldColumnName, $typeName);
-
- if ($columnDefinition['using'] ?? false) {
- $using = 'USING ' . $columnDefinition['using'];
- }
- }
-
- $sql->add(trim(sprintf(
- 'ALTER TABLE %s ALTER %s TYPE %s %s',
- $quoteName,
- $oldColumnName,
- $typeName,
- $using ?? ''
- )));
- }
-
- public function getDefaultValueDeclarationSQL(AbstractPlatform $platform, Column $column): string
- {
- $defaultValue = $column->getDefault();
- if ($defaultValue instanceof Expression) {
- return ' DEFAULT ' . $defaultValue->getValue(new PostgresGrammar());
- }
-
- return $platform->getDefaultValueDeclarationSQL($column->toArray());
- }
-
- public function typeChangeBreaksDefaultValue(ColumnDiff $columnDiff): bool
- {
- $oldTypeIsNumeric = $this->isNumericType($columnDiff->fromColumn);
- $newTypeIsNumeric = $this->isNumericType($columnDiff->column);
-
- $isNumeric = ! ($oldTypeIsNumeric && $newTypeIsNumeric && $columnDiff->column->getAutoincrement());
-
- return $columnDiff->hasChanged('type') && $isNumeric;
- }
-
- public function isNumericType(?Column $column): bool
- {
- $type = $column ? $column->getType() : null;
-
- return $type instanceof IntegerType || $type instanceof BigIntType;
- }
-
- public function quoteName(AbstractPlatform $platform, TableDiff $diff): string
- {
- return $diff
- ->getName($platform)
- ->getQuotedName($platform);
- }
-
- public function getOldColumnComment(ColumnDiff $columnDiff): ?string
- {
- return $columnDiff->fromColumn ? $this->getColumnComment($columnDiff->fromColumn) : null;
- }
-
- public function getColumnComment(Column $column): ?string
- {
- return $column->getComment();
- }
-}
diff --git a/tests.sh b/tests.sh
index c9040a9..c5a4636 100755
--- a/tests.sh
+++ b/tests.sh
@@ -8,6 +8,7 @@ sed -e "s/\${USERNAME}/postgres/" \
phpunit.xml.dist > phpunit.xml
COMPOSER_MEMORY_LIMIT=-1 composer update
composer lint
+php vendor/bin/phpunit -c phpunit.xml --migrate-configuration
if [ "x$EXCLUDE_GROUP" != "x" ]; then
php -d pcov.directory='.' vendor/bin/phpunit \
--exclude-group $EXCLUDE_GROUP \
diff --git a/tests/Functional/Connection/ConnectionTest.php b/tests/Functional/Connection/ConnectionTest.php
index e0de76f..2eeff4a 100644
--- a/tests/Functional/Connection/ConnectionTest.php
+++ b/tests/Functional/Connection/ConnectionTest.php
@@ -4,6 +4,7 @@
namespace Umbrellio\Postgres\Tests\Functional\Connection;
+use Generator;
use Illuminate\Database\Connection;
use Illuminate\Database\SQLiteConnection;
use Illuminate\Foundation\Testing\Concerns\InteractsWithDatabase;
@@ -11,6 +12,8 @@
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
+use PHPUnit\Framework\Attributes\DataProvider;
+use PHPUnit\Framework\Attributes\Test;
use Umbrellio\Postgres\Connectors\ConnectionFactory;
use Umbrellio\Postgres\Schema\Blueprint;
use Umbrellio\Postgres\Tests\_data\CustomSQLiteConnection;
@@ -24,9 +27,7 @@ class ConnectionTest extends FunctionalTestCase
protected $emulatePrepares = true;
- /**
- * @test
- */
+ #[Test]
public function connectionFactory(): void
{
$factory = new ConnectionFactory(app());
@@ -34,9 +35,7 @@ public function connectionFactory(): void
$this->assertInstanceOf(SQLiteConnection::class, $factory->make(config('database.connections.sqlite')));
}
- /**
- * @test
- */
+ #[Test]
public function resolverFor(): void
{
Connection::resolverFor('sqlite', function ($connection, $database, $prefix, $config) {
@@ -51,10 +50,8 @@ public function resolverFor(): void
);
}
- /**
- * @test
- * @dataProvider boolDataProvider
- */
+ #[Test]
+ #[DataProvider('boolDataProvider')]
public function boolTrueBindingsWorks($value)
{
$table = 'test_table';
@@ -70,10 +67,8 @@ public function boolTrueBindingsWorks($value)
$this->assertSame(1, $result->count());
}
- /**
- * @test
- * @dataProvider intDataProvider
- */
+ #[Test]
+ #[DataProvider('intDataProvider')]
public function intBindingsWorks($value)
{
$table = 'test_table';
@@ -89,9 +84,7 @@ public function intBindingsWorks($value)
$this->assertSame(1, $result->count());
}
- /**
- * @test
- */
+ #[Test]
public function stringBindingsWorks()
{
$table = 'test_table';
@@ -107,9 +100,7 @@ public function stringBindingsWorks()
$this->assertSame(1, $result->count());
}
- /**
- * @test
- */
+ #[Test]
public function nullBindingsWorks()
{
$table = 'test_table';
@@ -126,10 +117,8 @@ public function nullBindingsWorks()
$this->assertSame(1, $result->count());
}
- /**
- * @test
- * @dataProvider dateDataProvider
- */
+ #[Test]
+ #[DataProvider('dateDataProvider')]
public function dateTimeBindingsWorks($value)
{
$table = 'test_table';
@@ -145,19 +134,19 @@ public function dateTimeBindingsWorks($value)
$this->assertSame(1, $result->count());
}
- public function boolDataProvider()
+ public static function boolDataProvider(): Generator
{
yield 'true' => [true];
yield 'false' => [false];
}
- public function intDataProvider()
+ public static function intDataProvider(): Generator
{
yield 'zero' => [0];
yield 'non-zero' => [10];
}
- public function dateDataProvider()
+ public static function dateDataProvider(): Generator
{
yield 'as string' => ['2019-01-01 13:12:22'];
yield 'as Carbon object' => [new Carbon('2019-01-01 13:12:22')];
diff --git a/tests/Functional/Schema/CreateIndexTest.php b/tests/Functional/Schema/CreateIndexTest.php
index 4388430..aa597e3 100644
--- a/tests/Functional/Schema/CreateIndexTest.php
+++ b/tests/Functional/Schema/CreateIndexTest.php
@@ -11,6 +11,8 @@
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
+use PHPUnit\Framework\Attributes\DataProvider;
+use PHPUnit\Framework\Attributes\Test;
use Umbrellio\Postgres\Helpers\IndexAssertions;
use Umbrellio\Postgres\Helpers\TableAssertions;
use Umbrellio\Postgres\Schema\Blueprint;
@@ -26,61 +28,8 @@ class CreateIndexTest extends FunctionalTestCase
use InteractsWithDatabase;
- /**
- * @test
- */
- public function createIndexIfNotExists(): 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');
- }
-
- /**
- * @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
- */
+ #[Test]
+ #[DataProvider('provideIndexes')]
public function createPartialUnique(string $expected, Closure $callback): void
{
Schema::create('test_table', function (Blueprint $table) use ($callback) {
@@ -109,9 +58,7 @@ public function createPartialUnique(string $expected, Closure $callback): void
$this->notSeeIndex('test_table_name_unique');
}
- /**
- * @test
- */
+ #[Test]
public function createSpecifyIndex(): void
{
Schema::create('test_table', function (Blueprint $table) {
@@ -127,7 +74,7 @@ public function createSpecifyIndex(): void
);
}
- public function provideIndexes(): Generator
+ public static function provideIndexes(): Generator
{
yield ['', function (Blueprint $table) {
$table->uniquePartial('name');
@@ -218,9 +165,7 @@ function (Blueprint $table) {
];
}
- /**
- * @test
- */
+ #[Test]
public function addExcludeConstraints(): void
{
DB::statement('CREATE EXTENSION IF NOT EXISTS btree_gist');
@@ -251,9 +196,7 @@ public function addExcludeConstraints(): void
$this->dontSeeConstraint('test_table', 'test_table_period_start_period_end_excl');
}
- /**
- * @test
- */
+ #[Test]
public function addCheckConstraints(): void
{
Schema::create('test_table', function (Blueprint $table) {
@@ -282,9 +225,7 @@ public function addCheckConstraints(): void
}
}
- /**
- * @test
- */
+ #[Test]
public function dropCheckConstraints(): void
{
Schema::create('test_table', function (Blueprint $table) {
@@ -331,14 +272,14 @@ private function createIndexDefinition(): void
$this->seeIndex('test_table_name_unique');
}
- private function provideSuccessData(): Generator
+ private static function provideSuccessData(): Generator
{
yield [1, '2019-01-01', '2019-01-31'];
yield [2, '2019-02-15', '2019-04-20'];
yield [3, '2019-03-07', '2019-06-24'];
}
- private function provideWrongData(): Generator
+ private static function provideWrongData(): Generator
{
yield [4, '2019-01-01', '2019-01-31'];
yield [1, '2019-07-15', '2019-04-20'];
diff --git a/tests/Functional/Schema/CreateTableTest.php b/tests/Functional/Schema/CreateTableTest.php
index 4070584..44fd01a 100644
--- a/tests/Functional/Schema/CreateTableTest.php
+++ b/tests/Functional/Schema/CreateTableTest.php
@@ -6,6 +6,7 @@
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Schema;
+use PHPUnit\Framework\Attributes\Test;
use Umbrellio\Postgres\Helpers\ColumnAssertions;
use Umbrellio\Postgres\Helpers\TableAssertions;
use Umbrellio\Postgres\Schema\Blueprint;
@@ -19,9 +20,7 @@ class CreateTableTest extends FunctionalTestCase
use ColumnAssertions;
- /**
- * @test
- */
+ #[Test]
public function createSimple(): void
{
Schema::create('test_table', function (Blueprint $table) {
@@ -36,9 +35,7 @@ public function createSimple(): void
$this->seeTable('test_table');
}
- /**
- * @test
- */
+ #[Test]
public function columnAssertions(): void
{
Schema::create('test_table', function (Blueprint $table) {
@@ -53,7 +50,7 @@ public function columnAssertions(): void
$this->assertSameTable(['id', 'name', 'field_comment', 'field_default'], 'test_table');
$this->assertPostgresTypeColumn('test_table', 'id', 'integer');
- $this->assertLaravelTypeColumn('test_table', 'name', 'string');
+ $this->assertLaravelTypeColumn('test_table', 'name', 'varchar');
$this->assertPostgresTypeColumn('test_table', 'name', 'character varying');
$this->assertDefaultOnColumn('test_table', 'field_default', '123');
@@ -62,45 +59,4 @@ public function columnAssertions(): void
$this->assertDefaultOnColumn('test_table', 'name');
$this->assertCommentOnColumn('test_table', 'name');
}
-
- /**
- * @test
- */
- public function createViaLike(): void
- {
- Schema::create('test_table', function (Blueprint $table) {
- $table->increments('id');
- $table->string('name');
- });
-
- Schema::create('test_table2', function (Blueprint $table) {
- $table->like('test_table');
- });
-
- $this->seeTable('test_table');
- $this->seeTable('test_table2');
- $this->assertCompareTables('test_table', 'test_table2');
- }
-
- /**
- * @test
- */
- public function createViaLikeIncludingAll(): void
- {
- Schema::create('test_table', function (Blueprint $table) {
- $table->increments('id');
- $table->string('name')
- ->unique();
- });
-
- Schema::create('test_table2', function (Blueprint $table) {
- $table->like('test_table')
- ->includingAll();
- $table->ifNotExists();
- });
-
- $this->seeTable('test_table');
- $this->seeTable('test_table2');
- $this->assertCompareTables('test_table', 'test_table2');
- }
}
diff --git a/tests/Functional/Schema/CreateViewTest.php b/tests/Functional/Schema/CreateViewTest.php
deleted file mode 100644
index d304f21..0000000
--- a/tests/Functional/Schema/CreateViewTest.php
+++ /dev/null
@@ -1,74 +0,0 @@
-increments('id');
- $table->string('name');
- });
- }
-
- protected function tearDown(): void
- {
- Schema::dropIfExists('test_table');
-
- parent::tearDown();
- }
-
- /**
- * @test
- */
- public function createFacadeView(): void
- {
- Schema::createView('test_view', 'select * from test_table where name is not null');
-
- $this->seeView('test_view');
- $this->assertSameView(
- 'select test_table.id, test_table.name from test_table where (test_table.name is not null);',
- 'test_view'
- );
-
- Schema::dropView('test_view');
- $this->notSeeView('test_view');
- }
-
- /**
- * @test
- */
- public function createBlueprintView(): void
- {
- Schema::table('test_table', function (Blueprint $table) {
- $table->createView('test_view', 'select * from test_table where name is not null');
- });
-
- $this->seeView('test_view');
- $this->assertSameView(
- 'select test_table.id, test_table.name from test_table where (test_table.name is not null);',
- 'test_view'
- );
-
- Schema::table('users', function (Blueprint $table) {
- $table->dropView('test_view');
- });
-
- $this->notSeeView('test_view');
- }
-}
diff --git a/tests/Functional/Schema/GetForeignKeysTest.php b/tests/Functional/Schema/GetForeignKeysTest.php
deleted file mode 100644
index 90081dd..0000000
--- a/tests/Functional/Schema/GetForeignKeysTest.php
+++ /dev/null
@@ -1,74 +0,0 @@
-increments('id');
- $table->string('name');
- });
-
- Schema::create('test_foreign_table2', function (Blueprint $table) {
- $table->increments('id');
- $table->string('name');
- });
-
- Schema::create('test_table', function (Blueprint $table) {
- $table->increments('id');
- $table->string('name');
- $table->bigInteger('test1_id');
- $table->bigInteger('test2_id');
- $table->foreign(['test1_id'])->references('id')->on('test_foreign_table1');
- $table->foreign(['test2_id'])->references('id')->on('test_foreign_table2');
- });
- }
-
- protected function tearDown(): void
- {
- Schema::dropIfExists('test_table');
- Schema::dropIfExists('test_foreign_table1');
- Schema::dropIfExists('test_foreign_table2');
-
- parent::tearDown();
- }
-
- /**
- * @test
- */
- public function getForeignKeys(): void
- {
- $foreignKeys = Schema::getForeignKeys('test_table');
-
- $this->assertSame(
- (array) $foreignKeys[0],
- [
- 'source_column_name' => 'test1_id',
- 'target_table_name' => 'test_foreign_table1',
- 'target_column_name' => 'id',
- ]
- );
-
- $this->assertSame(
- (array) $foreignKeys[1],
- [
- 'source_column_name' => 'test2_id',
- 'target_table_name' => 'test_foreign_table2',
- 'target_column_name' => 'id',
- ]
- );
- }
-}
diff --git a/tests/Functional/Subscribers/ChangeColumnSubscriberTest.php b/tests/Functional/Subscribers/ChangeColumnSubscriberTest.php
deleted file mode 100644
index a691ac9..0000000
--- a/tests/Functional/Subscribers/ChangeColumnSubscriberTest.php
+++ /dev/null
@@ -1,382 +0,0 @@
-blueprint = new Blueprint('some_table');
- $this->postgresGrammar = new PostgresGrammar();
- $this->subscriber = new SchemaAlterTableChangeColumnSubscriber();
- $this->platform = new PostgreSqlPlatform();
- }
-
- /**
- * @test
- */
- public function getSubscriberEvents(): void
- {
- $this->assertSame([Events::onSchemaAlterTableChangeColumn], $this->subscriber->getSubscribedEvents());
- }
-
- /**
- * @test
- * @group forPHP7
- * @dataProvider provideSchemas
- */
- public function changeSchema7(string $column, Closure $callback, array $expectedSQL): void
- {
- $callback($this->blueprint, $column);
- $eventArgs = $this->getEventArgsForColumn($column);
- $this->subscriber->onSchemaAlterTableChangeColumn($eventArgs);
-
- $this->assertSame($expectedSQL, $eventArgs->getSql());
- }
-
- /**
- * @test
- * @group forPHP8
- * @dataProvider provideSchemas
- */
- public function changeSchema8(string $column, Closure $callback, array $expectedSQL): void
- {
- $callback($this->blueprint, $column);
- $eventArgs = $this->getEventArgsForColumn($column, 'tableColumn');
- $this->subscriber->onSchemaAlterTableChangeColumn($eventArgs);
-
- $this->assertSame($expectedSQL, $eventArgs->getSql());
- }
-
- public function provideSchemas(): Generator
- {
- yield $this->dropCommentCase();
- yield $this->changeCommentCase();
- yield $this->dropNotNullCase();
- yield $this->createSequenceCase();
- yield $this->dropDefaultCase();
- yield $this->setSimpleDefaultCase();
- yield $this->setExpressionDefaultCase();
- yield $this->changeTypeWithUsingCase();
- yield $this->changeLengthCase();
- }
-
- private function getEventArgsForColumn(
- string $columnName,
- string $argumentName = 'tableColumn'
- ): SchemaAlterTableChangeColumnEventArgs {
- /** @var PostgresConnection $connection */
- $connection = DB::connection();
- $schemaManager = $connection->getDoctrineSchemaManager();
-
- $this->columns = [];
- foreach ($this->getListColumns() as $listColumn) {
- $this->columns[] = ReflectionHelper::invokePrivateMethod(
- $schemaManager,
- '_getPortableTableColumnDefinition',
- [
- $argumentName => $listColumn,
- ]
- );
- }
-
- $this->table = new Table('some_table', $this->columns);
-
- $this->tableDiff = (new Comparator())->diffTable(
- $this->table,
- $this
- ->getStaticMethod(ChangeColumn::class, 'getTableWithColumnChanges')
- ->invoke(null, $this->blueprint, $this->table)
- );
-
- foreach ($this->tableDiff->changedColumns as $columnDiff) {
- if ($columnDiff->oldColumnName !== $columnName) {
- continue;
- }
- $this->columnDiff = $columnDiff;
- }
-
- return new SchemaAlterTableChangeColumnEventArgs($this->columnDiff, $this->tableDiff, $this->platform);
- }
-
- private function dropCommentCase(): array
- {
- return [
- 'some_comment',
- function (Blueprint $table, string $column) {
- $table->string($column)
- ->nullable(false)
- ->change();
- },
- ['ALTER TABLE some_table ALTER some_comment SET NOT NULL'],
- ];
- }
-
- private function changeCommentCase(): array
- {
- return [
- 'some_comment',
- function (Blueprint $table, string $column) {
- $table->string($column)
- ->comment('new_comment')
- ->change();
- },
- ["COMMENT ON COLUMN some_table.some_comment IS 'new_comment'"],
- ];
- }
-
- private function dropNotNullCase(): array
- {
- return [
- 'some_integer_default',
- function (Blueprint $table, string $column) {
- $table->integer($column)
- ->nullable()
- ->change();
- },
- ['ALTER TABLE some_table ALTER some_integer_default DROP NOT NULL'],
- ];
- }
-
- private function createSequenceCase(): array
- {
- return [
- 'some_integer_default',
- function (Blueprint $table, string $column) {
- $table->increments($column)
- ->change();
- },
- [
- 'CREATE SEQUENCE some_table_some_integer_default_seq',
- "SELECT setval('some_table_some_integer_default_seq', (SELECT MAX(some_integer_default) FROM some_table))",
- "ALTER TABLE some_table ALTER some_integer_default SET DEFAULT nextval('some_table_some_integer_default_seq')",
- ],
- ];
- }
-
- private function dropDefaultCase(): array
- {
- return [
- 'some_key',
- function (Blueprint $table, string $column) {
- $table->integer($column)
- ->change();
- },
- [
- 'ALTER TABLE some_table ALTER some_key DROP DEFAULT',
- 'ALTER TABLE some_table ALTER some_key TYPE INT USING some_key::INT',
- ],
- ];
- }
-
- private function setSimpleDefaultCase(): array
- {
- return [
- 'some_comment',
- function (Blueprint $table, string $column) {
- $table->string($column)
- ->default('some_default')
- ->change();
- },
- ["ALTER TABLE some_table ALTER some_comment SET DEFAULT 'some_default'"],
- ];
- }
-
- private function setExpressionDefaultCase(): array
- {
- return [
- 'some_comment',
- function (Blueprint $table, string $column) {
- $table->string($column)
- ->default(new Expression("('some_string:' || some_comment)::character varying"))
- ->change();
- },
- [
- "ALTER TABLE some_table ALTER some_comment SET DEFAULT ('some_string:' || some_comment)::character varying",
- ],
- ];
- }
-
- private function changeTypeWithUsingCase(): array
- {
- return [
- 'some_integer_default',
- function (Blueprint $table, string $column) {
- $table
- ->text($column)
- ->default(null)
- ->using(sprintf("('[some_exp:' || %s || ']')::character varying", $column))
- ->change();
- },
- [
- 'ALTER TABLE some_table ALTER some_integer_default DROP DEFAULT',
- "ALTER TABLE some_table ALTER some_integer_default TYPE TEXT USING ('[some_exp:' || some_integer_default || ']')::character varying",
- ],
- ];
- }
-
- private function changeLengthCase(): array
- {
- return [
- 'some_comment',
- function (Blueprint $table, string $column) {
- $table->string($column, 75)
- ->change();
- },
- ['ALTER TABLE some_table ALTER some_comment TYPE VARCHAR(75)'],
- ];
- }
-
- private function getListColumns(): array
- {
- return [
- $this->getDefinitionSomeKeySequence(),
- $this->getDefinitionSomeString(),
- $this->getDefinitionSomeStringDefault(),
- $this->getDefinitionSomeIntegerDefault(),
- $this->getDefinitionSomeComment(),
- ];
- }
-
- private function getStaticMethod($class, $method): ReflectionMethod
- {
- $method = new ReflectionMethod($class, $method);
- $method->setAccessible(true);
-
- return $method;
- }
-
- private function getDefinitionSomeKeySequence(): array
- {
- return [
- 'attnum' => 1,
- 'field' => 'some_key',
- 'type' => 'int8',
- 'complete_type' => 'bigint',
- 'domain_type' => null,
- 'domain_complete_type' => null,
- 'isnotnull' => true,
- 'pri' => 't',
- 'default' => "nextval('some_table_some_key_seq'::regclass)",
- 'comment' => null,
- ];
- }
-
- private function getDefinitionSomeString(): array
- {
- return [
- 'attnum' => 2,
- 'field' => 'some_string',
- 'type' => 'varchar',
- 'complete_type' => 'character varying',
- 'domain_type' => null,
- 'domain_complete_type' => null,
- 'isnotnull' => false,
- 'pri' => null,
- 'default' => null,
- 'comment' => null,
- ];
- }
-
- private function getDefinitionSomeStringDefault(): array
- {
- return [
- 'attnum' => 3,
- 'field' => 'some_string_default',
- 'type' => 'varchar',
- 'complete_type' => 'character varying',
- 'domain_type' => null,
- 'domain_complete_type' => null,
- 'isnotnull' => true,
- 'pri' => null,
- 'default' => "'some_default_value'::character varying",
- 'comment' => null,
- ];
- }
-
- private function getDefinitionSomeIntegerDefault(): array
- {
- return [
- 'attnum' => 4,
- 'field' => 'some_integer_default',
- 'type' => 'int4',
- 'complete_type' => 'integer',
- 'domain_type' => null,
- 'domain_complete_type' => null,
- 'isnotnull' => true,
- 'pri' => null,
- 'default' => 1,
- 'comment' => null,
- ];
- }
-
- private function getDefinitionSomeComment(): array
- {
- return [
- 'attnum' => 5,
- 'field' => 'some_comment',
- 'type' => 'varchar',
- 'complete_type' => 'character varying',
- 'domain_type' => null,
- 'domain_complete_type' => null,
- 'isnotnull' => false,
- 'pri' => null,
- 'default' => null,
- 'comment' => 'some_comment_value',
- ];
- }
-}
diff --git a/tests/Unit/Extensions/AbstractExtensionTest.php b/tests/Unit/Extensions/AbstractExtensionTest.php
index 94a515f..1f1fab9 100644
--- a/tests/Unit/Extensions/AbstractExtensionTest.php
+++ b/tests/Unit/Extensions/AbstractExtensionTest.php
@@ -6,6 +6,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\ServiceProvider;
+use PHPUnit\Framework\Attributes\Test;
use Umbrellio\Postgres\Extensions\AbstractComponent;
use Umbrellio\Postgres\Extensions\AbstractExtension;
use Umbrellio\Postgres\Extensions\Exceptions\MacroableMissedException;
@@ -15,9 +16,7 @@
class AbstractExtensionTest extends TestCase
{
- /**
- * @test
- */
+ #[Test]
public function registerInvalidExtension(): void
{
$abstractExtension = new ExtensionStub();
@@ -28,9 +27,7 @@ public function registerInvalidExtension(): void
$abstractExtension::register();
}
- /**
- * @test
- */
+ #[Test]
public function registerWithInvalidMixin(): void
{
$abstractExtension = new InvalidExtensionStub();
@@ -71,7 +68,7 @@ public static function getName(): string
public static function getMixins(): array
{
return [
- InvalidComponentStub::class => Blueprint::class,
+ \Umbrellio\Postgres\Tests\Unit\Extensions\InvalidComponentStub::class => Blueprint::class,
];
}
}
diff --git a/tests/Unit/Schema/Blueprint/IndexTest.php b/tests/Unit/Schema/Blueprint/IndexTest.php
index 41ab57b..4badc08 100644
--- a/tests/Unit/Schema/Blueprint/IndexTest.php
+++ b/tests/Unit/Schema/Blueprint/IndexTest.php
@@ -2,10 +2,12 @@
declare(strict_types=1);
-namespace Umbrellio\Postgres\Unit\Schema\Blueprint;
+namespace Umbrellio\Postgres\Tests\Unit\Schema\Blueprint;
use Closure;
use Generator;
+use PHPUnit\Framework\Attributes\DataProvider;
+use PHPUnit\Framework\Attributes\Test;
use Umbrellio\Postgres\Schema\Blueprint;
use Umbrellio\Postgres\Tests\TestCase;
use Umbrellio\Postgres\Tests\Unit\Helpers\BlueprintAssertions;
@@ -23,17 +25,15 @@ protected function setUp(): void
$this->initializeMock(static::TABLE);
}
- /**
- * @test
- * @dataProvider provideExcludeConstraints
- */
+ #[Test]
+ #[DataProvider('provideExcludeConstraints')]
public function addConstraint(Closure $callback, string $expectedSQL): void
{
$callback($this->blueprint);
$this->assertSameSql($expectedSQL);
}
- public function provideExcludeConstraints(): Generator
+ public static function provideExcludeConstraints(): Generator
{
yield [
static function (Blueprint $table) {
diff --git a/tests/Unit/Schema/Blueprint/PartitionTest.php b/tests/Unit/Schema/Blueprint/PartitionTest.php
index e396e47..83dee94 100644
--- a/tests/Unit/Schema/Blueprint/PartitionTest.php
+++ b/tests/Unit/Schema/Blueprint/PartitionTest.php
@@ -2,10 +2,11 @@
declare(strict_types=1);
-namespace Umbrellio\Postgres\Unit\Schema\Blueprint;
+namespace Umbrellio\Postgres\Tests\Unit\Schema\Blueprint;
use Illuminate\Support\Carbon;
use InvalidArgumentException;
+use PHPUnit\Framework\Attributes\Test;
use Umbrellio\Postgres\Tests\TestCase;
use Umbrellio\Postgres\Tests\Unit\Helpers\BlueprintAssertions;
@@ -22,18 +23,14 @@ protected function setUp(): void
$this->initializeMock(static::TABLE);
}
- /**
- * @test
- */
+ #[Test]
public function detachPartition(): void
{
$this->blueprint->detachPartition('some_partition');
$this->assertSameSql('alter table "test_table" detach partition some_partition');
}
- /**
- * @test
- */
+ #[Test]
public function attachPartitionRangeInt(): void
{
$this->blueprint->attachPartition('some_partition')
@@ -44,9 +41,7 @@ public function attachPartitionRangeInt(): void
$this->assertSameSql('alter table "test_table" attach partition some_partition for values from (10) to (100)');
}
- /**
- * @test
- */
+ #[Test]
public function attachPartitionFailedWithoutForValuesPart(): void
{
$this->blueprint->attachPartition('some_partition');
@@ -54,9 +49,7 @@ public function attachPartitionFailedWithoutForValuesPart(): void
$this->runToSql();
}
- /**
- * @test
- */
+ #[Test]
public function attachPartitionRangeDates(): void
{
$today = Carbon::today();
@@ -74,9 +67,7 @@ public function attachPartitionRangeDates(): void
));
}
- /**
- * @test
- */
+ #[Test]
public function attachPartitionStringDates(): void
{
$today = '2010-01-01';
@@ -94,54 +85,42 @@ public function attachPartitionStringDates(): void
));
}
- /**
- * @test
- */
+ #[Test]
public function addingTsrangeColumn()
{
$this->blueprint->tsrange('foo');
$this->assertSameSql('alter table "test_table" add column "foo" tsrange not null');
}
- /**
- * @test
- */
+ #[Test]
public function addingTstzrangeColumn()
{
$this->blueprint->tstzrange('foo');
$this->assertSameSql('alter table "test_table" add column "foo" tstzrange not null');
}
- /**
- * @test
- */
+ #[Test]
public function addingDaterangeColumn()
{
$this->blueprint->daterange('foo');
$this->assertSameSql('alter table "test_table" add column "foo" daterange not null');
}
- /**
- * @test
- */
+ #[Test]
public function addingNumericColumnWithVariablePrecicion()
{
$this->blueprint->numeric('foo');
$this->assertSameSql('alter table "test_table" add column "foo" numeric not null');
}
- /**
- * @test
- */
+ #[Test]
public function addingNumericColumnWithDefinedPrecicion()
{
$this->blueprint->numeric('foo', 8);
$this->assertSameSql('alter table "test_table" add column "foo" numeric(8) not null');
}
- /**
- * @test
- */
+ #[Test]
public function addingNumericColumnWithDefinedPrecicionAndScope()
{
$this->blueprint->numeric('foo', 8, 2);
diff --git a/tests/Unit/Schema/Types/DateRangeTypeTest.php b/tests/Unit/Schema/Types/DateRangeTypeTest.php
index dff0867..8f877cc 100644
--- a/tests/Unit/Schema/Types/DateRangeTypeTest.php
+++ b/tests/Unit/Schema/Types/DateRangeTypeTest.php
@@ -2,46 +2,38 @@
declare(strict_types=1);
-namespace Umbrellio\Postgres\Unit\Schema\Types;
+namespace Umbrellio\Postgres\Tests\Unit\Schema\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
+use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
+use Doctrine\DBAL\Types\Type;
+use PHPUnit\Framework\Attributes\Test;
use Umbrellio\Postgres\Schema\Types\DateRangeType;
use Umbrellio\Postgres\Tests\TestCase;
class DateRangeTypeTest extends TestCase
{
- /**
- * @var AbstractPlatform
- */
- private $abstractPlatform;
+ private AbstractPlatform $abstractPlatform;
- /**
- * @var DateRangeType
- */
- private $type;
+ private Type $type;
protected function setUp(): void
{
parent::setUp();
- $this->type = $this
- ->getMockBuilder(DateRangeType::class)
- ->disableOriginalConstructor()
- ->getMockForAbstractClass();
- $this->abstractPlatform = $this->getMockForAbstractClass(AbstractPlatform::class);
+ $this->type = new DateRangeType();
+ $this->abstractPlatform = $this
+ ->getMockBuilder(PostgreSQLPlatform::class)
+ ->getMock();
}
- /**
- * @test
- */
+ #[Test]
public function getSQLDeclaration(): void
{
$this->assertSame(DateRangeType::TYPE_NAME, $this->type->getSQLDeclaration([], $this->abstractPlatform));
}
- /**
- * @test
- */
+ #[Test]
public function getTypeName(): void
{
$this->assertSame(DateRangeType::TYPE_NAME, $this->type->getName());
diff --git a/tests/Unit/Schema/Types/NumericTypeTest.php b/tests/Unit/Schema/Types/NumericTypeTest.php
index 1780be3..ce9e4c4 100644
--- a/tests/Unit/Schema/Types/NumericTypeTest.php
+++ b/tests/Unit/Schema/Types/NumericTypeTest.php
@@ -2,46 +2,38 @@
declare(strict_types=1);
-namespace Umbrellio\Postgres\Unit\Schema\Types;
+namespace Umbrellio\Postgres\Tests\Unit\Schema\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
+use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
+use Doctrine\DBAL\Types\Type;
+use PHPUnit\Framework\Attributes\Test;
use Umbrellio\Postgres\Schema\Types\NumericType;
use Umbrellio\Postgres\Tests\TestCase;
class NumericTypeTest extends TestCase
{
- /**
- * @var AbstractPlatform
- */
- private $abstractPlatform;
+ private AbstractPlatform $abstractPlatform;
- /**
- * @var NumericType
- */
- private $type;
+ private Type $type;
protected function setUp(): void
{
parent::setUp();
- $this->type = $this
- ->getMockBuilder(NumericType::class)
- ->disableOriginalConstructor()
- ->getMockForAbstractClass();
- $this->abstractPlatform = $this->getMockForAbstractClass(AbstractPlatform::class);
+ $this->type = new NumericType();
+ $this->abstractPlatform = $this
+ ->getMockBuilder(PostgreSQLPlatform::class)
+ ->getMock();
}
- /**
- * @test
- */
+ #[Test]
public function getSQLDeclaration(): void
{
$this->assertSame(NumericType::TYPE_NAME, $this->type->getSQLDeclaration([], $this->abstractPlatform));
}
- /**
- * @test
- */
+ #[Test]
public function getTypeName(): void
{
$this->assertSame(NumericType::TYPE_NAME, $this->type->getName());
diff --git a/tests/Unit/Schema/Types/TsRangeTypeTest.php b/tests/Unit/Schema/Types/TsRangeTypeTest.php
index a8326bf..88eb823 100644
--- a/tests/Unit/Schema/Types/TsRangeTypeTest.php
+++ b/tests/Unit/Schema/Types/TsRangeTypeTest.php
@@ -2,46 +2,38 @@
declare(strict_types=1);
-namespace Umbrellio\Postgres\Unit\Schema\Types;
+namespace Umbrellio\Postgres\Tests\Unit\Schema\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
+use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
+use Doctrine\DBAL\Types\Type;
+use PHPUnit\Framework\Attributes\Test;
use Umbrellio\Postgres\Schema\Types\TsRangeType;
use Umbrellio\Postgres\Tests\TestCase;
class TsRangeTypeTest extends TestCase
{
- /**
- * @var AbstractPlatform
- */
- private $abstractPlatform;
+ private AbstractPlatform $abstractPlatform;
- /**
- * @var TsRangeType
- */
- private $type;
+ private Type $type;
protected function setUp(): void
{
parent::setUp();
- $this->type = $this
- ->getMockBuilder(TsRangeType::class)
- ->disableOriginalConstructor()
- ->getMockForAbstractClass();
- $this->abstractPlatform = $this->getMockForAbstractClass(AbstractPlatform::class);
+ $this->type = new TsRangeType();
+ $this->abstractPlatform = $this
+ ->getMockBuilder(PostgreSQLPlatform::class)
+ ->getMock();
}
- /**
- * @test
- */
+ #[Test]
public function getSQLDeclaration(): void
{
$this->assertSame(TsRangeType::TYPE_NAME, $this->type->getSQLDeclaration([], $this->abstractPlatform));
}
- /**
- * @test
- */
+ #[Test]
public function getTypeName(): void
{
$this->assertSame(TsRangeType::TYPE_NAME, $this->type->getName());
diff --git a/tests/Unit/Schema/Types/TsTzRangeTypeTest.php b/tests/Unit/Schema/Types/TsTzRangeTypeTest.php
index 680c1b6..de6002c 100644
--- a/tests/Unit/Schema/Types/TsTzRangeTypeTest.php
+++ b/tests/Unit/Schema/Types/TsTzRangeTypeTest.php
@@ -2,46 +2,38 @@
declare(strict_types=1);
-namespace Umbrellio\Postgres\Unit\Schema\Types;
+namespace Umbrellio\Postgres\Tests\Unit\Schema\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
+use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
+use Doctrine\DBAL\Types\Type;
+use PHPUnit\Framework\Attributes\Test;
use Umbrellio\Postgres\Schema\Types\TsTzRangeType;
use Umbrellio\Postgres\Tests\TestCase;
class TsTzRangeTypeTest extends TestCase
{
- /**
- * @var AbstractPlatform
- */
- private $abstractPlatform;
+ private AbstractPlatform $abstractPlatform;
- /**
- * @var TsRangeType
- */
- private $type;
+ private Type $type;
protected function setUp(): void
{
parent::setUp();
- $this->type = $this
- ->getMockBuilder(TsTzRangeType::class)
- ->disableOriginalConstructor()
- ->getMockForAbstractClass();
- $this->abstractPlatform = $this->getMockForAbstractClass(AbstractPlatform::class);
+ $this->type = new TsTzRangeType();
+ $this->abstractPlatform = $this
+ ->getMockBuilder(PostgreSQLPlatform::class)
+ ->getMock();
}
- /**
- * @test
- */
+ #[Test]
public function getSQLDeclaration(): void
{
$this->assertSame(TsTzRangeType::TYPE_NAME, $this->type->getSQLDeclaration([], $this->abstractPlatform));
}
- /**
- * @test
- */
+ #[Test]
public function getTypeName(): void
{
$this->assertSame(TsTzRangeType::TYPE_NAME, $this->type->getName());