From 8f07516a901aa0162af293104d7faf5e94596ba8 Mon Sep 17 00:00:00 2001 From: Korben Dallas Date: Fri, 3 May 2024 00:26:00 +0200 Subject: [PATCH] Added support PHP 8.3|8.4 (#83) * Added support php 8.3|8.4 --- .github/workflows/ci.yml | 76 ++++++------------- .gitignore | 4 +- composer.json | 12 +-- tests.sh | 3 +- .../Collections/LTreeCollectionTest.php | 60 +++++++-------- tests/functional/Helpers/LTreeHelperTest.php | 25 ++---- tests/functional/Helpers/LTreeNodeTest.php | 54 ++++--------- tests/functional/Models/LTreeModelTest.php | 38 ++++------ .../Providers/LTreeServiceProviderTest.php | 7 +- .../Relations/BelongsToTreelTest.php | 46 +++++------ .../Resources/LTreeResourceTest.php | 5 +- tests/functional/Types/LTreeTypeTest.php | 46 ++++------- 12 files changed, 139 insertions(+), 237 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8789576..3dcc318 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,10 +13,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' @@ -26,14 +26,17 @@ jobs: timeout-minutes: 20 strategy: matrix: - operating_system: - - ubuntu-latest - php_versions: - - '7.4' + operating_system: [ubuntu-latest] + experimental: [false] + php_versions: ['8.3'] + include: + - operating_system: 'ubuntu-latest' + php_versions: '8.4' + experimental: true fail-fast: false env: PHP_CS_FIXER_FUTURE_MODE: '0' - name: 'Lint PHP' + name: 'Linter / PHP ${{ matrix.php_versions }} ' steps: - name: 'Checkout' uses: actions/checkout@v2 @@ -63,58 +66,24 @@ jobs: - name: 'Setup problem matchers for PHPUnit' run: 'echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"' - name: 'Install PHP dependencies with Composer' + continue-on-error: ${{ matrix.experimental }} run: COMPOSER_MEMORY_LIMIT=-1 composer install --prefer-dist --no-progress --no-suggest --optimize-autoloader working-directory: './' - name: 'Linting PHP source files' + continue-on-error: ${{ matrix.experimental }} run: 'vendor/bin/ecs check --config=ecs.php .' test: strategy: fail-fast: false matrix: - experimental: - - false - operating_system: - - ubuntu-latest - postgres: - - '10' - - '11' - - '12' - php_versions: - - '7.3' - - '7.4' - - '8.0' + experimental: [false] + operating_system: [ubuntu-latest] + postgres: ['10', '11', '12', '13', '14', '15'] + php_versions: ['8.3'] include: - operating_system: ubuntu-latest - postgres: '9.6' - php_versions: '7.3' - experimental: false - - operating_system: ubuntu-latest - postgres: '9.6' - php_versions: '7.4' - experimental: false - - operating_system: ubuntu-latest - postgres: '10' - php_versions: '8.0' - experimental: true - - operating_system: ubuntu-latest - postgres: '11' - php_versions: '8.0' - experimental: true - - operating_system: ubuntu-latest - postgres: '12' - php_versions: '8.0' - experimental: true - - operating_system: ubuntu-latest - postgres: '13' - php_versions: '8.0' - experimental: true - - operating_system: ubuntu-latest - postgres: '14' - php_versions: '8.1' - experimental: true - - operating_system: ubuntu-latest - postgres: '15' - php_versions: '8.2' + postgres: '16' + php_versions: '8.4' experimental: true runs-on: '${{ matrix.operating_system }}' services: @@ -158,10 +127,11 @@ 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 }} run: COMPOSER_MEMORY_LIMIT=-1 composer install --prefer-dist --no-progress --no-suggest --optimize-autoloader working-directory: './' - name: 'Run Unit Tests with PHPUnit' @@ -172,9 +142,11 @@ jobs: -e "s/\${DATABASE}/${{ env.DB_NAME }}/" \ -e "s/\${HOST}/${{ env.DB_HOST }}/" \ phpunit.xml.dist > phpunit.xml + ./vendor/bin/phpunit -c phpunit.xml --migrate-configuration ./vendor/bin/phpunit \ --stderr \ - --coverage-clover build/logs/clover.xml + --coverage-clover build/logs/clover.xml \ + --coverage-text working-directory: './' - name: 'Upload coverage results to Coveralls' if: ${{ !matrix.experimental }} diff --git a/.gitignore b/.gitignore index d838c5a..d222f26 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,10 @@ /vendor /.idea .ecs_cache +.phpunit.cache phpunit.xml -/build/* +/build .phpunit.result.cache .DS_Store composer.lock + diff --git a/composer.json b/composer.json index 059496b..8c25b8b 100644 --- a/composer.json +++ b/composer.json @@ -21,15 +21,15 @@ ], "license": "MIT", "require": { - "php": "^7.3|^7.4|^8.0|^8.1|^8.2", - "laravel/framework": "^5.8|^6.20.26|^7.0|^8.40|^9.0|^10.0|^11.0", - "doctrine/dbal": "^2.9|^3.0", - "umbrellio/laravel-pg-extensions": "^5.0|^6.0", - "umbrellio/laravel-common-objects": "^2.3" + "php": "^8.3|^8.4", + "laravel/framework": "^11.0", + "doctrine/dbal": "^3.0", + "umbrellio/laravel-pg-extensions": "^7.0", + "umbrellio/laravel-common-objects": "*" }, "require-dev": { "umbrellio/code-style-php": "^1.0", - "orchestra/testbench": "^3.5|^6.0|^4.0|^7.0|^8.0|^9.0", + "orchestra/testbench": "^9.0", "php-coveralls/php-coveralls": "^2.1", "squizlabs/php_codesniffer": "^3.5" }, diff --git a/tests.sh b/tests.sh index 7e1eb8c..17d8fe1 100755 --- a/tests.sh +++ b/tests.sh @@ -8,4 +8,5 @@ sed -e "s/\${USERNAME}/postgres/" \ phpunit.xml.dist > phpunit.xml COMPOSER_MEMORY_LIMIT=-1 composer update composer lint -php -d pcov.directory='.' vendor/bin/phpunit --coverage-html build --coverage-text +php vendor/bin/phpunit -c phpunit.xml --migrate-configuration +php -d xdebug.mode=coverage -d memory_limit=-1 vendor/bin/phpunit --coverage-html build --coverage-text diff --git a/tests/functional/Collections/LTreeCollectionTest.php b/tests/functional/Collections/LTreeCollectionTest.php index 443fd8a..f2ef403 100644 --- a/tests/functional/Collections/LTreeCollectionTest.php +++ b/tests/functional/Collections/LTreeCollectionTest.php @@ -5,6 +5,8 @@ namespace Umbrellio\LTree\tests\functional\Resources; use Generator; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use Umbrellio\LTree\Exceptions\LTreeUndefinedNodeException; use Umbrellio\LTree\Interfaces\LTreeModelInterface; use Umbrellio\LTree\tests\_data\Models\CategoryStub; @@ -12,9 +14,7 @@ class LTreeCollectionTest extends LTreeBaseTestCase { - /** - * @test - */ + #[Test] public function collectionCanBeConvertedIntoTree() { $tree = $this @@ -26,15 +26,13 @@ public function collectionCanBeConvertedIntoTree() $this->assertSame($tree, $tree->getChildren()[0]->getParent()); } - /** - * @test - * @dataProvider provideNoConstencyTree - */ - public function loadMissingNodes(array $ids, array $expected): void + #[Test] + #[DataProvider('provideNoConstencyTree')] + public function loadMissingNodes(array $items, array $expected): void { $this->assertSame( CategoryStub::query() - ->whereKey($ids) + ->whereKey($items) ->get() ->toTree() ->toCollection() @@ -47,15 +45,13 @@ public function loadMissingNodes(array $ids, array $expected): void ); } - /** - * @test - * @dataProvider providePartialConstencyTree - */ - public function withoutLoadMissingForPartialTree(array $ids, array $expected): void + #[Test] + #[DataProvider('providePartialConstencyTree')] + public function withoutLoadMissingForPartialTree(array $items, array $expected): void { $this->assertSame( CategoryStub::query() - ->whereKey($ids) + ->whereKey($items) ->get() ->toTree(true, false) ->toCollection() @@ -68,23 +64,21 @@ public function withoutLoadMissingForPartialTree(array $ids, array $expected): v ); } - public function provideTreeWithoutLeaves(): Generator + public static function provideTreeWithoutLeaves(): Generator { yield 'without_leaves' => [ - 'ids' => [10, 7, 12], + 'items' => [10, 7, 12], 'expected' => [1, 3, 6, 11], ]; } - /** - * @test - * @dataProvider provideTreeWithoutLeaves - */ - public function withoutLeaves(array $ids, array $expected): void + #[Test] + #[DataProvider('provideTreeWithoutLeaves')] + public function withoutLeaves(array $items, array $expected): void { $this->assertSame( CategoryStub::query() - ->whereKey($ids) + ->whereKey($items) ->get() ->withLeaves(false) ->toTree() @@ -98,25 +92,23 @@ public function withoutLeaves(array $ids, array $expected): void ); } - public function provideNoConstency(): Generator + public static function provideNoConstency(): Generator { yield 'non_consistent_without_loading' => [ - 'ids' => [1, 6, 8], + 'items' => [1, 6, 8], 'expected' => [1, 6, 8], 'loadMissing' => false, ]; } - /** - * @test - * @dataProvider provideNoConstency - */ - public function withoutLoadMissingNodes(array $ids, array $expected): void + #[Test] + #[DataProvider('provideNoConstency')] + public function withoutLoadMissingNodes(array $items, array $expected, bool $loadMissing): void { $this->expectException(LTreeUndefinedNodeException::class); $this->assertSame( CategoryStub::query() - ->whereKey($ids) + ->whereKey($items) ->get() ->toTree(true, false) ->toCollection() @@ -129,10 +121,10 @@ public function withoutLoadMissingNodes(array $ids, array $expected): void ); } - public function provideNoConstencyTree(): Generator + public static function provideNoConstencyTree(): Generator { yield 'non_consistent_with_loading' => [ - 'ids' => [7, 3, 12], + 'items' => [7, 3, 12], 'expected' => [1, 3, 7, 11, 12], ]; yield 'consistent' => [ @@ -140,7 +132,7 @@ public function provideNoConstencyTree(): Generator 'expected' => [1, 3, 7], ]; } - public function providePartialConstencyTree(): Generator + public static function providePartialConstencyTree(): Generator { yield 'partial with single branch without single nodes' => [ 'items' => [3, 6, 7, 8, 9, 10], diff --git a/tests/functional/Helpers/LTreeHelperTest.php b/tests/functional/Helpers/LTreeHelperTest.php index 3e74254..9a843af 100644 --- a/tests/functional/Helpers/LTreeHelperTest.php +++ b/tests/functional/Helpers/LTreeHelperTest.php @@ -4,15 +4,14 @@ namespace Umbrellio\LTree\tests\functional\Helpers; +use PHPUnit\Framework\Attributes\Test; use Umbrellio\LTree\Interfaces\LTreeModelInterface; use Umbrellio\LTree\tests\_data\Models\CategoryStub; use Umbrellio\LTree\tests\LTreeBaseTestCase; class LTreeHelperTest extends LTreeBaseTestCase { - /** - * @test - */ + #[Test] public function createViaServiceRoot(): void { $node = $this->createCategory([ @@ -25,9 +24,7 @@ public function createViaServiceRoot(): void $this->assertSame('15', $node->getLtreePath(LTreeModelInterface::AS_STRING)); } - /** - * @test - */ + #[Test] public function moveSubtrees(): void { $nodes = $this->getCategories(); @@ -44,9 +41,7 @@ public function moveSubtrees(): void $this->assertSame(11, $root->getLtreeParentId()); } - /** - * @test - */ + #[Test] public function proxyColumns(): void { $nodeMoscow = $this->findNodeByPath('1.3'); @@ -69,9 +64,7 @@ public function proxyColumns(): void $this->assertNull($nodeMoscow->name); } - /** - * @test - */ + #[Test] public function deleteRoot(): void { $root = $this->getRoot(); @@ -81,9 +74,7 @@ public function deleteRoot(): void $this->assertFalse($root::descendantsOf($root)->exists()); } - /** - * @test - */ + #[Test] public function deleteSubtree(): void { $root = $this->getRoot(); @@ -94,9 +85,7 @@ public function deleteSubtree(): void $this->assertSame(1, $root::descendantsOf($root)->count()); } - /** - * @test - */ + #[Test] public function deleteViaServiceSubtree(): void { $root = $this->getRoot(); diff --git a/tests/functional/Helpers/LTreeNodeTest.php b/tests/functional/Helpers/LTreeNodeTest.php index 13531ec..c1e1927 100644 --- a/tests/functional/Helpers/LTreeNodeTest.php +++ b/tests/functional/Helpers/LTreeNodeTest.php @@ -7,6 +7,8 @@ use Generator; use Illuminate\Database\Eloquent\Model; use InvalidArgumentException; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use Umbrellio\LTree\Collections\LTreeCollection; use Umbrellio\LTree\Exceptions\LTreeReflectionException; use Umbrellio\LTree\Exceptions\LTreeUndefinedNodeException; @@ -17,9 +19,7 @@ class LTreeNodeTest extends LTreeBaseTestCase { private $hits; - /** - * @test - */ + #[Test] public function nodeCantHaveUnknownParent() { $this->expectException(LTreeUndefinedNodeException::class); @@ -28,9 +28,7 @@ public function nodeCantHaveUnknownParent() ->toTree(); } - /** - * @test - */ + #[Test] public function nodeCantBeParentToItself() { $this->expectException(LTreeReflectionException::class); @@ -39,9 +37,7 @@ public function nodeCantBeParentToItself() ->toTree(); } - /** - * @test - */ + #[Test] public function findSuccess(): void { $tree = $this @@ -58,10 +54,8 @@ public function findSuccess(): void $this->assertNotNull($tree->findInTree(1)->findInTree(2)); } - /** - * @test - * @dataProvider provideUnknownNodes - */ + #[Test] + #[DataProvider('provideUnknownNodes')] public function findFail($node): void { $tree = $this @@ -70,7 +64,7 @@ public function findFail($node): void $this->assertNull($tree->findInTree($node)); } - public function provideUnknownNodes(): Generator + public static function provideUnknownNodes(): Generator { yield '-1' => [ 'node' => -1, @@ -83,9 +77,7 @@ public function provideUnknownNodes(): Generator ]; } - /** - * @test - */ + #[Test] public function countDescendants(): void { $tree = $this @@ -99,9 +91,7 @@ public function countDescendants(): void $this->assertSame(1, $tree->findInTree(11)->countDescendants()); } - /** - * @test - */ + #[Test] public function each() { $tree = $this @@ -120,18 +110,14 @@ public function each() $this->assertCount(0, $collection); } - /** - * @test - */ + #[Test] public function toTreeOnEmptyCollection(): void { $collection = new LTreeCollection(); $this->assertInstanceOf(LTreeNode::class, $collection->toTree()); } - /** - * @test - */ + #[Test] public function toCollection(): void { $tree = $this @@ -147,9 +133,7 @@ public function toCollection(): void } } - /** - * @test - */ + #[Test] public function toTreeArray(): void { $formatter = static function ($item) { @@ -177,9 +161,7 @@ public function toTreeArray(): void $this->assertArrayNotHasKey('id', $node); } - /** - * @test - */ + #[Test] public function nodePresenter() { $tree = $this @@ -194,9 +176,7 @@ public function nodePresenter() $this->assertNotNull($node->model->getTable()); } - /** - * @test - */ + #[Test] public function sortFail(): void { $tree = $this @@ -206,9 +186,7 @@ public function sortFail(): void $tree->sortTree(['name']); } - /** - * @test - */ + #[Test] public function sort() { $tree = $this diff --git a/tests/functional/Models/LTreeModelTest.php b/tests/functional/Models/LTreeModelTest.php index 45d3105..2dfa330 100644 --- a/tests/functional/Models/LTreeModelTest.php +++ b/tests/functional/Models/LTreeModelTest.php @@ -5,21 +5,21 @@ namespace Umbrellio\LTree\tests\functional\Models; use Generator; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use Umbrellio\LTree\tests\_data\Models\CategoryStub; use Umbrellio\LTree\tests\LTreeBaseTestCase; class LTreeModelTest extends LTreeBaseTestCase { - /** - * @test - * @dataProvider provideLevels - */ + #[Test] + #[DataProvider('provideLevels')] public function getLtreeLevel(string $path, int $level): void { $this->assertSame($level, $this ->findNodeByPath($path) ->getLtreeLevel()); } - public function provideLevels(): Generator + public static function provideLevels(): Generator { yield 'root' => [ 'path' => '1', @@ -35,30 +35,26 @@ public function provideLevels(): Generator ]; } - /** - * @test - * @dataProvider providePaths - */ + #[Test] + #[DataProvider('providePaths')] public function parentsOf(array $paths, int $expectedCount): void { $this->assertCount($expectedCount, CategoryStub::parentsOf($paths)->get()); } - public function providePaths(): Generator + public static function providePaths(): Generator { yield 'single_as_array' => [ 'paths' => ['11.12'], - 'expected' => 2, + 'expectedCount' => 2, ]; yield 'all_as_array' => [ 'paths' => ['11.12', '1.2.5'], - 'expected' => 5, + 'expectedCount' => 5, ]; } - /** - * @test - */ + #[Test] public function root(): void { $node = $this->findNodeByPath('1.2.5'); @@ -68,9 +64,7 @@ public function root(): void } } - /** - * @test - */ + #[Test] public function ancestors(): void { $root = $this->getRoot(); @@ -80,9 +74,7 @@ public function ancestors(): void $this->assertTrue($node2->isParentOf(5)); } - /** - * @test - */ + #[Test] public function getAncestorByLevel(): void { $root = $this->getRoot(); @@ -100,9 +92,7 @@ public function getAncestorByLevel(): void $this->assertSame($node8->getAncestorByLevel(3)->getKey(), $node6->getKey()); } - /** - * @test - */ + #[Test] public function children(): void { $node11 = $this->findNodeByPath('11'); diff --git a/tests/functional/Providers/LTreeServiceProviderTest.php b/tests/functional/Providers/LTreeServiceProviderTest.php index 5eb7761..1e2e613 100644 --- a/tests/functional/Providers/LTreeServiceProviderTest.php +++ b/tests/functional/Providers/LTreeServiceProviderTest.php @@ -5,16 +5,15 @@ namespace Umbrellio\LTree\tests\functional\Providers; use Illuminate\Support\Facades\App; +use PHPUnit\Framework\Attributes\Test; use Umbrellio\LTree\Interfaces\LTreeServiceInterface; use Umbrellio\LTree\Services\LTreeService; use Umbrellio\LTree\tests\FunctionalTestCase; class LTreeServiceProviderTest extends FunctionalTestCase { - /** - * @test - */ - public function testProviderInit(): void + #[Test] + public function providerInit(): void { $service = App::make(LTreeServiceInterface::class); $this->assertInstanceOf(LTreeService::class, $service); diff --git a/tests/functional/Relations/BelongsToTreelTest.php b/tests/functional/Relations/BelongsToTreelTest.php index 8c31b05..d788bcb 100644 --- a/tests/functional/Relations/BelongsToTreelTest.php +++ b/tests/functional/Relations/BelongsToTreelTest.php @@ -5,6 +5,8 @@ namespace Umbrellio\LTree\tests\functional\Relations; use Generator; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use Umbrellio\LTree\Exceptions\InvalidTraitInjectionClass; use Umbrellio\LTree\tests\_data\Models\CategorySomeStub; use Umbrellio\LTree\tests\_data\Models\ProductStub; @@ -12,42 +14,40 @@ class BelongsToTreelTest extends LTreeBaseTestCase { - public function provideBelongsParentsTree(): Generator + public static function provideBelongsParentsTree(): Generator { yield 'two_levels' => [ 'path' => '11.12', 'count' => 2, - 'expected1' => 11, - 'expected2' => 12, - 'expected3' => null, + 'level1' => 11, + 'level2' => 12, + 'level3' => null, ]; yield 'three_levels' => [ 'path' => '1.2.5', 'count' => 3, - 'expected1' => 1, - 'expected2' => 2, - 'expected3' => 5, + 'level1' => 1, + 'level2' => 2, + 'level3' => 5, ]; } - public function provideBelongsDescendantsTree(): Generator + public static function provideBelongsDescendantsTree(): Generator { yield 'with_descendants' => [ 'path' => '1.3', 'count' => 6, - 'expected1' => 3, - 'expected2' => 6, - 'expected3' => 10, - 'expected4' => 8, - 'expected5' => 9, - 'expected6' => 7, + 'level1' => 3, + 'level2' => 6, + 'level3' => 10, + 'level4' => 8, + 'level5' => 9, + 'level6' => 7, ]; } - /** - * @test - * @dataProvider provideBelongsParentsTree - */ + #[Test] + #[DataProvider('provideBelongsParentsTree')] public function getBelongsToParentsTree($path, $count, $level1, $level2, $level3) { $product = $this->createProduct([]); @@ -70,10 +70,8 @@ public function getBelongsToParentsTree($path, $count, $level1, $level2, $level3 $this->assertSame($level3, optional($itemWith->categoryAncestorsTree->get(2))->getKey()); } - /** - * @test - * @dataProvider provideBelongsDescendantsTree - */ + #[Test] + #[DataProvider('provideBelongsDescendantsTree')] public function getBelongsToDescendantsTree($path, $count, $level1, $level2, $level3, $level4, $level5, $level6) { $product = $this->createProduct([]); @@ -103,9 +101,7 @@ public function getBelongsToDescendantsTree($path, $count, $level1, $level2, $le $this->assertSame($level6, optional($itemWith->categoryDescendantsTree->get(5))->getKey()); } - /** - * @test - */ + #[Test] public function missingParentsLtreeModel(): void { $rootSome = $this->getCategorySome([ diff --git a/tests/functional/Resources/LTreeResourceTest.php b/tests/functional/Resources/LTreeResourceTest.php index 8c551a2..30ed1dc 100644 --- a/tests/functional/Resources/LTreeResourceTest.php +++ b/tests/functional/Resources/LTreeResourceTest.php @@ -5,15 +5,14 @@ namespace Umbrellio\LTree\tests\functional\Resources; use Illuminate\Http\Request; +use PHPUnit\Framework\Attributes\Test; use Umbrellio\LTree\tests\_data\Models\CategoryStub; use Umbrellio\LTree\tests\_data\Models\CategoryStubResourceCollection; use Umbrellio\LTree\tests\LTreeBaseTestCase; class LTreeResourceTest extends LTreeBaseTestCase { - /** - * @test - */ + #[Test] public function resources(): void { $resource = new CategoryStubResourceCollection( diff --git a/tests/functional/Types/LTreeTypeTest.php b/tests/functional/Types/LTreeTypeTest.php index 0d580f8..73f5860 100644 --- a/tests/functional/Types/LTreeTypeTest.php +++ b/tests/functional/Types/LTreeTypeTest.php @@ -5,68 +5,54 @@ namespace Umbrellio\LTree\tests\functional\Types; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use Generator; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use Umbrellio\LTree\tests\FunctionalTestCase; use Umbrellio\LTree\Types\LTreeType; class LTreeTypeTest extends FunctionalTestCase { - /** - * @var AbstractPlatform - */ - private $abstractPlatform; - - /** - * @var LTreeType - */ - private $type; + private AbstractPlatform $abstractPlatform; + private LTreeType $type; protected function setUp(): void { parent::setUp(); - $this->type = $this - ->getMockBuilder(LTreeType::class) - ->disableOriginalConstructor() - ->getMockForAbstractClass(); - - $this->abstractPlatform = $this->getMockForAbstractClass(AbstractPlatform::class); + $this->type = new LTreeType(); + $this->abstractPlatform = new PostgreSQLPlatform(); } - /** - * @test - */ + #[Test] public function getSQLDeclaration(): void { $this->assertSame(LTreeType::TYPE_NAME, $this->type->getSQLDeclaration([], $this->abstractPlatform)); } - /** - * @dataProvider providePHPValues - * @test - */ + #[Test] + #[DataProvider('providePHPValues')] public function convertToPHPValue($value, $expected): void { $this->assertSame($expected, $this->type->convertToDatabaseValue($value, $this->abstractPlatform)); } - public function provideDatabaseValues(): Generator + public static function provideDatabaseValues(): Generator { yield [null, null]; yield ['1.2.3', [1, 2, 3]]; yield [1, [1]]; } - /** - * @dataProvider provideDatabaseValues - * @test - */ + #[Test] + #[DataProvider('provideDatabaseValues')] public function convertToDatabaseValue($value, $expected): void { $this->assertSame($expected, $this->type->convertToPHPValue($value, $this->abstractPlatform)); } - public function providePHPValues(): Generator + public static function providePHPValues(): Generator { yield [null, null]; yield [1, '1']; @@ -74,9 +60,7 @@ public function providePHPValues(): Generator yield [[1, 2, 3], '1.2.3']; } - /** - * @test - */ + #[Test] public function getTypeName(): void { $this->assertSame(LTreeType::TYPE_NAME, $this->type->getName());