From 19fd26c8f742ce33be24180075f505fb5e533984 Mon Sep 17 00:00:00 2001 From: Alexey Rogachev Date: Mon, 19 Feb 2024 01:52:47 +0600 Subject: [PATCH] Miscellaneous fixes (#98) * Simplify working with paths in README * Sync related to SimpleRuleFactory * Actualize badges * Improve wording --- .github/PULL_REQUEST_TEMPLATE.md | 1 - CHANGELOG.md | 2 +- README.md | 31 ++++++++++--------- .../MysqlItemTreeTraversal.php | 8 ++--- tests/Base/ManagerTest.php | 22 +++++-------- 5 files changed, 28 insertions(+), 36 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 4a3e8ace..6be5d587 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -3,4 +3,3 @@ | Is bugfix? | ✔️/❌ | New feature? | ✔️/❌ | Breaks BC? | ✔️/❌ -| Fixed issues | comma-separated list of tickets # fixed by the PR, if any diff --git a/CHANGELOG.md b/CHANGELOG.md index 495799b9..c5c78037 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +21,7 @@ - Enh #94: Decrease size for string columns from 128 to 126 for PostgreSQL optimization (@arogachev) - Enh #95: Backwards sync of changes with rbac-db package (@arogachev) - Bug #95: Handle null result when getting access tree using MySQL 5.7 (@arogachev) -- Chg #97: Rename `getAccessTree()` to `getHierarchy()` in `ItemsStorageInterface` (@arogachev) +- Chg #97: Rename `getAccessTree()` to `getHierarchy()` in `ItemsStorageInterface` implmentations (@arogachev) ## 2.0.0 April 20, 2023 diff --git a/README.md b/README.md index 9892b741..af5517e4 100644 --- a/README.md +++ b/README.md @@ -11,14 +11,23 @@ The package provides [Cycle Database](https://github.com/cycle/database) storage [![Latest Stable Version](https://poser.pugx.org/yiisoft/rbac-cycle-db/v/stable.png)](https://packagist.org/packages/yiisoft/rbac-cycle-db) [![Total Downloads](https://poser.pugx.org/yiisoft/rbac-cycle-db/downloads.png)](https://packagist.org/packages/yiisoft/rbac-cycle-db) [![Build status](https://github.com/yiisoft/rbac-cycle-db/workflows/build/badge.svg)](https://github.com/yiisoft/rbac-cycle-db/actions?query=workflow%3Abuild) -[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/yiisoft/rbac-cycle-db/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/rbac-cycle-db/?branch=master) -[![Code Coverage](https://scrutinizer-ci.com/g/yiisoft/rbac-cycle-db/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/rbac-cycle-db/?branch=master) +[![codecov](https://codecov.io/gh/yiisoft/rbac-cycle-db/graph/badge.svg?token=OAABFCCC7A)](https://codecov.io/gh/yiisoft/rbac-cycle-db) [![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Frbac-cycle-db%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/rbac-cycle-db/master) [![static analysis](https://github.com/yiisoft/rbac-cycle-db/workflows/static%20analysis/badge.svg)](https://github.com/yiisoft/rbac-cycle-db/actions?query=workflow%3A%22static+analysis%22) +[![type-coverage](https://shepherd.dev/github/yiisoft/rbac-cycle-db/coverage.svg)](https://shepherd.dev/github/yiisoft/rbac-cycle-db) + +Detailed build statuses: + +| RDBMS | Status | +|----------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| SQLite | [![SQLite status](https://github.com/yiisoft/rbac-cycle-db/workflows/sqlite/badge.svg)](https://github.com/yiisoft/rbac-cycle-db/actions?query=workflow%3Asqlite) | +| MySQL | [![MYSQL status](https://github.com/yiisoft/rbac-cycle-db/workflows/mysql/badge.svg)](https://github.com/yiisoft/rbac-cycle-db/actions?query=workflow%3Amysql) | +| PostgreSQL | [![MYSQL status](https://github.com/yiisoft/rbac-cycle-db/workflows/pgsql/badge.svg)](https://github.com/yiisoft/rbac-cycle-db/actions?query=workflow%3Apgsql) | +| Microsoft SQL Server | [![MYSQL status](https://github.com/yiisoft/rbac-cycle-db/workflows/mssql/badge.svg)](https://github.com/yiisoft/rbac-cycle-db/actions?query=workflow%3Amssql) | ## Requirements -- PHP 8.0 or higher. +- PHP 8.1 or higher. - In case of using with SQLite, minimal required version is 3.8.3. - In case of using with SQL Server, minimal required version of PDO is 5.11.1. @@ -88,18 +97,10 @@ use Cycle\Migrations\FileRepository; use Cycle\Migrations\Migrator; $migrationsSubfolders = ['items', 'assignments']; -$directories = []; -foreach (static::$migrationsSubfolders as $subfolder) { - $directories[] = implode(DIRECTORY_SEPARATOR, [ - dirname(__DIR__, 2), // Adjust this if your path is different. - 'vendor', - 'yiisoft', - 'rbac', - 'migrations', - $subfolder, - ]); -} - +$directories = array_map( + static fn (): string => dirname(__DIR__. 2), "/vendor/yiisoft/rbac-cycle-db/migrations/$subfolder", + $migrationsSubfolders, +); $config = new MigrationConfig([ 'directory' => $directories[0], // "vendorDirectories" are specified because "directory" option doesn't support multiple directories. In the end, it diff --git a/src/ItemTreeTraversal/MysqlItemTreeTraversal.php b/src/ItemTreeTraversal/MysqlItemTreeTraversal.php index be4894cc..5d6abb68 100644 --- a/src/ItemTreeTraversal/MysqlItemTreeTraversal.php +++ b/src/ItemTreeTraversal/MysqlItemTreeTraversal.php @@ -61,7 +61,7 @@ public function getParentRows(string $name): array public function getHierarchy(string $name): array { - $sql = "SELECT item.*, access_tree_base.children FROM ( + $sql = "SELECT item.*, hierarchy_base.children FROM ( SELECT child_name, MIN(TRIM(BOTH '$this->namesSeparator' FROM TRIM(BOTH child_name FROM raw_children))) as children @@ -69,10 +69,10 @@ public function getHierarchy(string $name): array SELECT @r AS child_name, @path := concat(@path, '$this->namesSeparator', @r) as raw_children, (SELECT @r := parent FROM $this->childrenTableName WHERE child = child_name LIMIT 1) AS parent FROM (SELECT @r := :name, @path := '') val, $this->childrenTableName - ) raw_access_tree_base + ) raw_hierarchy_base GROUP BY child_name - ) access_tree_base - LEFT JOIN $this->tableName AS item ON item.name = access_tree_base.child_name + ) hierarchy_base + LEFT JOIN $this->tableName AS item ON item.name = hierarchy_base.child_name WHERE item.name IS NOT NULL"; /** @psalm-var Hierarchy */ diff --git a/tests/Base/ManagerTest.php b/tests/Base/ManagerTest.php index bde29d33..cc5eb3ba 100644 --- a/tests/Base/ManagerTest.php +++ b/tests/Base/ManagerTest.php @@ -7,15 +7,14 @@ use Yiisoft\Rbac\AssignmentsStorageInterface; use Yiisoft\Rbac\Cycle\TransactionalManagerDecorator; use Yiisoft\Rbac\ItemsStorageInterface; -use Yiisoft\Rbac\Manager; use Yiisoft\Rbac\ManagerInterface; -use Yiisoft\Rbac\RuleFactoryInterface; use Yiisoft\Rbac\Tests\Common\ManagerConfigurationTestTrait; -use Yiisoft\Rbac\Tests\Support\SimpleRuleFactory; abstract class ManagerTest extends TestCase { - use ManagerConfigurationTestTrait; + use ManagerConfigurationTestTrait { + createManager as protected traitCreateManager; + } protected function tearDown(): void { @@ -33,18 +32,11 @@ protected function populateDatabase(): void protected function createManager( ?ItemsStorageInterface $itemsStorage = null, ?AssignmentsStorageInterface $assignmentsStorage = null, - ?RuleFactoryInterface $ruleFactory = null, ?bool $enableDirectPermissions = false ): ManagerInterface { - $arguments = [ - $itemsStorage ?? $this->createItemsStorage(), - $assignmentsStorage ?? $this->createAssignmentsStorage(), - $ruleFactory ?? new SimpleRuleFactory(), - ]; - if ($enableDirectPermissions !== null) { - $arguments[] = $enableDirectPermissions; - } - - return new TransactionalManagerDecorator(new Manager(...$arguments), $this->getDatabase()); + return new TransactionalManagerDecorator( + $this->traitCreateManager($itemsStorage, $assignmentsStorage, $enableDirectPermissions), + $this->getDatabase(), + ); } }