From 2c37e6e8403e242506f35d35d68e70b9e1421601 Mon Sep 17 00:00:00 2001 From: Korben Date: Thu, 2 May 2024 00:56:07 +0200 Subject: [PATCH] fix tests --- .github/workflows/ci.yml | 23 +- .gitignore | 2 + .run/Functional.run.xml | 14 + .run/Tests .run.xml | 14 + .run/Unit.run.xml | 14 + composer.json | 14 +- phpunit.xml.bak | 38 ++ src/PostgresConnection.php | 44 ++- src/Schema/Blueprint.php | 5 +- src/Schema/Grammars/PostgresGrammar.php | 10 +- ...SchemaAlterTableChangeColumnSubscriber.php | 242 ------------ tests.sh | 1 + .../Functional/Connection/ConnectionTest.php | 36 +- tests/Functional/Schema/CreateIndexTest.php | 43 +- tests/Functional/Schema/CreateTableTest.php | 19 +- tests/Functional/Schema/CreateViewTest.php | 11 +- .../Functional/Schema/GetForeignKeysTest.php | 7 +- .../ChangeColumnSubscriberTest.php | 367 ------------------ .../Unit/Extensions/AbstractExtensionTest.php | 11 +- tests/Unit/Schema/Blueprint/IndexTest.php | 10 +- tests/Unit/Schema/Blueprint/PartitionTest.php | 47 +-- tests/Unit/Schema/Types/DateRangeTypeTest.php | 32 +- tests/Unit/Schema/Types/NumericTypeTest.php | 32 +- tests/Unit/Schema/Types/TsRangeTypeTest.php | 32 +- tests/Unit/Schema/Types/TsTzRangeTypeTest.php | 32 +- 25 files changed, 241 insertions(+), 859 deletions(-) create mode 100644 .run/Functional.run.xml create mode 100644 .run/Tests .run.xml create mode 100644 .run/Unit.run.xml create mode 100644 phpunit.xml.bak delete mode 100644 src/Schema/Subscribers/SchemaAlterTableChangeColumnSubscriber.php delete mode 100644 tests/Functional/Subscribers/ChangeColumnSubscriberTest.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4767b1a..505b476 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,9 +36,6 @@ jobs: operating_system: - ubuntu-latest php_versions: - - '8.0' - - '8.1' - - '8.2' - '8.3' fail-fast: false env: @@ -85,27 +82,21 @@ jobs: exclude_group: ['WithSchema'] experimental: [false] operating_system: [ubuntu-latest] - postgres: ['10', '11', '12', '13'] - php_versions: ['8.0'] - phpunit_command: [--help] + postgres: ['10', '11', '12', '13', '14'] + php_versions: ['8.3'] + phpunit_command: [-c phpunit.xml --migrate-configuration] include: - operating_system: 'ubuntu-latest' - php_versions: '8.1' - postgres: '14' - coverage: false - experimental: false - phpunit_command: -c phpunit.xml --migrate-configuration - - operating_system: 'ubuntu-latest' - php_versions: '8.2' + php_versions: '8.3' postgres: '15' coverage: false - experimental: false + experimental: true phpunit_command: -c phpunit.xml --migrate-configuration - operating_system: 'ubuntu-latest' - php_versions: '8.2' + php_versions: '8.4' postgres: '16' coverage: false - experimental: false + experimental: true phpunit_command: -c phpunit.xml --migrate-configuration runs-on: '${{ matrix.operating_system }}' services: diff --git a/.gitignore b/.gitignore index 7fc91c6..6a8d4eb 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,6 @@ .ecs_cache phpunit.xml .phpunit.result.cache +.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/composer.json b/composer.json index aa45c0a..ffddd26 100644 --- a/composer.json +++ b/composer.json @@ -34,16 +34,16 @@ }, "require": { "ext-pdo": "*", - "php": "^8.0|^8.1|^8.2|^8.3", - "doctrine/dbal": "^2.9|^3.0", - "laravel/framework": "^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|^4.0|^5.0|^6.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" + "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.bak b/phpunit.xml.bak new file mode 100644 index 0000000..6a3f601 --- /dev/null +++ b/phpunit.xml.bak @@ -0,0 +1,38 @@ + + + + + ./src + + + ./src/.meta.php + + + + + + + + + + + + + + + + + + ./tests + + + diff --git a/src/PostgresConnection.php b/src/PostgresConnection.php index 218f038..7a74872 100644 --- a/src/PostgresConnection.php +++ b/src/PostgresConnection.php @@ -6,16 +6,16 @@ use DateTimeInterface; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Events; +use Doctrine\DBAL\DriverManager; +use Doctrine\DBAL\Platforms\AbstractPlatform; +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; @@ -68,9 +68,13 @@ public function useDefaultPostProcessor(): void public function getDoctrineConnection(): Connection { - $doctrineConnection = parent::getDoctrineConnection(); - $this->overrideDoctrineBehavior($doctrineConnection); - return $doctrineConnection; + return DriverManager::getConnection($this->getConfig()); + } + + public function getDatabasePlatform(): AbstractPlatform + { + return $this->getDoctrineConnection() + ->getDatabasePlatform(); } public function bindValues($statement, $bindings) @@ -124,7 +128,13 @@ 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); + } else { + $this + ->getDatabasePlatform() + ->registerDoctrineTypeMapping($typeClass, $type); + } } } @@ -137,20 +147,14 @@ 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); + } else { + $this + ->getDatabasePlatform() + ->registerDoctrineTypeMapping($typeClass, $type); + } } }); } - - 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/Grammars/PostgresGrammar.php b/src/Schema/Grammars/PostgresGrammar.php index 9bacf67..16e624f 100644 --- a/src/Schema/Grammars/PostgresGrammar.php +++ b/src/Schema/Grammars/PostgresGrammar.php @@ -50,7 +50,7 @@ public function compileDetachPartition(Blueprint $blueprint, Fluent $command): s ); } - public function compileCreateView(/** @scrutinizer ignore-unused */ Blueprint $blueprint, Fluent $command): string + public function compileCreateView(Blueprint $blueprint, Fluent $command): string { $materialize = $command->get('materialize') ? 'materialized' : ''; return implode(' ', array_filter([ @@ -63,7 +63,7 @@ public function compileCreateView(/** @scrutinizer ignore-unused */ Blueprint $b ])); } - public function compileDropView(/** @scrutinizer ignore-unused */ Blueprint $blueprint, Fluent $command): string + public function compileDropView(Blueprint $blueprint, Fluent $command): string { return 'drop view ' . $this->wrapTable($command->get('view')); } @@ -133,17 +133,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 fa4809c..2eeff4a 100644 --- a/tests/Functional/Connection/ConnectionTest.php +++ b/tests/Functional/Connection/ConnectionTest.php @@ -12,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; @@ -25,9 +27,7 @@ class ConnectionTest extends FunctionalTestCase protected $emulatePrepares = true; - /** - * @test - */ + #[Test] public function connectionFactory(): void { $factory = new ConnectionFactory(app()); @@ -35,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) { @@ -52,10 +50,8 @@ public function resolverFor(): void ); } - /** - * @test - * @dataProvider boolDataProvider - */ + #[Test] + #[DataProvider('boolDataProvider')] public function boolTrueBindingsWorks($value) { $table = 'test_table'; @@ -71,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'; @@ -90,9 +84,7 @@ public function intBindingsWorks($value) $this->assertSame(1, $result->count()); } - /** - * @test - */ + #[Test] public function stringBindingsWorks() { $table = 'test_table'; @@ -108,9 +100,7 @@ public function stringBindingsWorks() $this->assertSame(1, $result->count()); } - /** - * @test - */ + #[Test] public function nullBindingsWorks() { $table = 'test_table'; @@ -127,10 +117,8 @@ public function nullBindingsWorks() $this->assertSame(1, $result->count()); } - /** - * @test - * @dataProvider dateDataProvider - */ + #[Test] + #[DataProvider('dateDataProvider')] public function dateTimeBindingsWorks($value) { $table = 'test_table'; diff --git a/tests/Functional/Schema/CreateIndexTest.php b/tests/Functional/Schema/CreateIndexTest.php index 0e1f25f..f3def9c 100644 --- a/tests/Functional/Schema/CreateIndexTest.php +++ b/tests/Functional/Schema/CreateIndexTest.php @@ -11,6 +11,9 @@ use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; +use PHPUnit\Framework\Attributes\Test; use Umbrellio\Postgres\Helpers\IndexAssertions; use Umbrellio\Postgres\Helpers\TableAssertions; use Umbrellio\Postgres\Schema\Blueprint; @@ -26,9 +29,7 @@ class CreateIndexTest extends FunctionalTestCase use InteractsWithDatabase; - /** - * @test - */ + #[Test] public function createIndexIfNotExists(): void { Schema::create('test_table', function (Blueprint $table) { @@ -41,8 +42,10 @@ public function createIndexIfNotExists(): void }); $this->seeTable('test_table'); +// dd(Schema::getIndexListing('test_table')); Schema::table('test_table', function (Blueprint $table) { +// dd($table->hasIndex(['name'], true)); if (! $table->hasIndex(['name'], true)) { $table->unique(['name']); } @@ -51,10 +54,8 @@ public function createIndexIfNotExists(): void $this->seeIndex('test_table_name_unique'); } - /** - * @test - * @group WithSchema - */ + #[Test] + #[Group('WithSchema')] public function createIndexWithSchema(): void { $this->createIndexDefinition(); @@ -64,10 +65,8 @@ public function createIndexWithSchema(): void ); } - /** - * @test - * @group WithoutSchema - */ + #[Test] + #[Group('WithoutSchema')] public function createIndexWithoutSchema(): void { $this->createIndexDefinition(); @@ -77,10 +76,8 @@ public function createIndexWithoutSchema(): void ); } - /** - * @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 +106,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) { @@ -218,9 +213,7 @@ function (Blueprint $table) { ]; } - /** - * @test - */ + #[Test] public function addExcludeConstraints(): void { DB::statement('CREATE EXTENSION IF NOT EXISTS btree_gist'); @@ -251,9 +244,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 +273,7 @@ public function addCheckConstraints(): void } } - /** - * @test - */ + #[Test] public function dropCheckConstraints(): void { Schema::create('test_table', function (Blueprint $table) { diff --git a/tests/Functional/Schema/CreateTableTest.php b/tests/Functional/Schema/CreateTableTest.php index 4070584..acf9628 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'); @@ -63,9 +60,7 @@ public function columnAssertions(): void $this->assertCommentOnColumn('test_table', 'name'); } - /** - * @test - */ + #[Test] public function createViaLike(): void { Schema::create('test_table', function (Blueprint $table) { @@ -82,9 +77,7 @@ public function createViaLike(): void $this->assertCompareTables('test_table', 'test_table2'); } - /** - * @test - */ + #[Test] public function createViaLikeIncludingAll(): void { Schema::create('test_table', function (Blueprint $table) { diff --git a/tests/Functional/Schema/CreateViewTest.php b/tests/Functional/Schema/CreateViewTest.php index d304f21..d341d85 100644 --- a/tests/Functional/Schema/CreateViewTest.php +++ b/tests/Functional/Schema/CreateViewTest.php @@ -2,10 +2,11 @@ declare(strict_types=1); -namespace Umbrellio\Postgres\Tests\Functional; +namespace Umbrellio\Postgres\Tests\Functional\Schema; use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Support\Facades\Schema; +use PHPUnit\Framework\Attributes\Test; use Umbrellio\Postgres\Helpers\ViewAssertions; use Umbrellio\Postgres\Schema\Blueprint; use Umbrellio\Postgres\Tests\FunctionalTestCase; @@ -33,9 +34,7 @@ protected function tearDown(): void parent::tearDown(); } - /** - * @test - */ + #[Test] public function createFacadeView(): void { Schema::createView('test_view', 'select * from test_table where name is not null'); @@ -50,9 +49,7 @@ public function createFacadeView(): void $this->notSeeView('test_view'); } - /** - * @test - */ + #[Test] public function createBlueprintView(): void { Schema::table('test_table', function (Blueprint $table) { diff --git a/tests/Functional/Schema/GetForeignKeysTest.php b/tests/Functional/Schema/GetForeignKeysTest.php index 90081dd..e6e616c 100644 --- a/tests/Functional/Schema/GetForeignKeysTest.php +++ b/tests/Functional/Schema/GetForeignKeysTest.php @@ -2,10 +2,11 @@ declare(strict_types=1); -namespace Umbrellio\Postgres\Tests\Functional; +namespace Umbrellio\Postgres\Tests\Functional\Schema; use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Support\Facades\Schema; +use PHPUnit\Framework\Attributes\Test; use Umbrellio\Postgres\Schema\Blueprint; use Umbrellio\Postgres\Tests\FunctionalTestCase; @@ -46,9 +47,7 @@ protected function tearDown(): void parent::tearDown(); } - /** - * @test - */ + #[Test] public function getForeignKeys(): void { $foreignKeys = Schema::getForeignKeys('test_table'); diff --git a/tests/Functional/Subscribers/ChangeColumnSubscriberTest.php b/tests/Functional/Subscribers/ChangeColumnSubscriberTest.php deleted file mode 100644 index a974152..0000000 --- a/tests/Functional/Subscribers/ChangeColumnSubscriberTest.php +++ /dev/null @@ -1,367 +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 - * @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 static function provideSchemas(): Generator - { - yield 'drop_comment' => static::dropCommentCase(); - yield 'change_comment' => static::changeCommentCase(); - yield 'drop_not_null' => static::dropNotNullCase(); - yield 'create_sequence' => static::createSequenceCase(); - yield 'drop_default' => static::dropDefaultCase(); - yield 'set_simple_default' => static::setSimpleDefaultCase(); - yield 'set_expression_default' => static::setExpressionDefaultCase(); - yield 'change_type_with_using' => static::changeTypeWithUsingCase(); - yield 'change_length' => static::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 static 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 static 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 static 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 static 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 static 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 static 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 static 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 static 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 static 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 93817e2..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,10 +25,8 @@ 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); 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());