From 80a27cc785689ce26ec2c9c4a89012fa70b4c613 Mon Sep 17 00:00:00 2001 From: kievan Date: Mon, 22 Jul 2019 17:13:17 +0300 Subject: [PATCH 1/4] add custom Configuration dependency injection, tests passing --- src/Manager/AttributeManager.php | 3 ++- src/Manager/PolicyRuleManager.php | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Manager/AttributeManager.php b/src/Manager/AttributeManager.php index f962444..64af8ec 100644 --- a/src/Manager/AttributeManager.php +++ b/src/Manager/AttributeManager.php @@ -4,6 +4,7 @@ use PhpAbac\Configuration\Configuration; +use PhpAbac\Configuration\ConfigurationInterface; use PhpAbac\Model\{ AbstractAttribute, Attribute, @@ -25,7 +26,7 @@ class AttributeManager implements AttributeManagerInterface * 'getter_prefix' => Prefix to add before getter name (default)'get' * 'getter_name_transformation_function' => Function to apply on the getter name ( before adding prefix ) (default)'ucfirst' */ - public function __construct(Configuration $configuration, array $options = []) + public function __construct(ConfigurationInterface $configuration, array $options = []) { $this->attributes = $configuration->getAttributes(); diff --git a/src/Manager/PolicyRuleManager.php b/src/Manager/PolicyRuleManager.php index a84a063..48097e7 100644 --- a/src/Manager/PolicyRuleManager.php +++ b/src/Manager/PolicyRuleManager.php @@ -2,8 +2,7 @@ namespace PhpAbac\Manager; -use PhpAbac\Configuration\Configuration; - +use PhpAbac\Configuration\ConfigurationInterface; use PhpAbac\Model\{ PolicyRule, PolicyRuleAttribute @@ -16,7 +15,7 @@ class PolicyRuleManager implements PolicyRuleManagerInterface /** @var array **/ private $rules = []; - public function __construct(Configuration $configuration, AttributeManager $attributeManager) + public function __construct(ConfigurationInterface $configuration, AttributeManager $attributeManager) { $this->attributeManager = $attributeManager; $this->rules = $configuration->getRules(); From 93f3cb1aff98ff9a56515c2b3c319bed4f675afe Mon Sep 17 00:00:00 2001 From: kievan Date: Tue, 23 Jul 2019 10:46:06 +0300 Subject: [PATCH 2/4] code cleanup, code style, tests passing --- src/Manager/AttributeManager.php | 16 ++++++++-------- src/Manager/PolicyRuleManager.php | 9 ++++----- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/Manager/AttributeManager.php b/src/Manager/AttributeManager.php index 64af8ec..adc2136 100644 --- a/src/Manager/AttributeManager.php +++ b/src/Manager/AttributeManager.php @@ -2,14 +2,11 @@ namespace PhpAbac\Manager; -use PhpAbac\Configuration\Configuration; - +use InvalidArgumentException; use PhpAbac\Configuration\ConfigurationInterface; -use PhpAbac\Model\{ - AbstractAttribute, - Attribute, - EnvironmentAttribute -}; +use PhpAbac\Model\AbstractAttribute; +use PhpAbac\Model\Attribute; +use PhpAbac\Model\EnvironmentAttribute; class AttributeManager implements AttributeManagerInterface { @@ -25,6 +22,9 @@ class AttributeManager implements AttributeManagerInterface * Options list : * 'getter_prefix' => Prefix to add before getter name (default)'get' * 'getter_name_transformation_function' => Function to apply on the getter name ( before adding prefix ) (default)'ucfirst' + * + * @param ConfigurationInterface $configuration + * @param array $options */ public function __construct(ConfigurationInterface $configuration, array $options = []) { @@ -97,7 +97,7 @@ private function retrieveClassicAttribute(Attribute $attribute, $object, array $ $getter = $this->getter_prefix.call_user_func($this->getter_name_transformation_function, $property); // Use is_callable, instead of method_exists, to deal with __call magic method if (!is_callable([$propertyValue,$getter])) { - throw new \InvalidArgumentException('There is no getter for the "'.$attribute->getProperty().'" attribute for object "'.get_class($propertyValue).'" with getter "'.$getter.'"'); + throw new InvalidArgumentException('There is no getter for the "'.$attribute->getProperty().'" attribute for object "'.get_class($propertyValue).'" with getter "'.$getter.'"'); } if (($propertyValue = call_user_func_array([ $propertyValue, diff --git a/src/Manager/PolicyRuleManager.php b/src/Manager/PolicyRuleManager.php index 48097e7..a0ede80 100644 --- a/src/Manager/PolicyRuleManager.php +++ b/src/Manager/PolicyRuleManager.php @@ -2,11 +2,10 @@ namespace PhpAbac\Manager; +use InvalidArgumentException; use PhpAbac\Configuration\ConfigurationInterface; -use PhpAbac\Model\{ - PolicyRule, - PolicyRuleAttribute -}; +use PhpAbac\Model\PolicyRule; +use PhpAbac\Model\PolicyRuleAttribute; class PolicyRuleManager implements PolicyRuleManagerInterface { @@ -24,7 +23,7 @@ public function __construct(ConfigurationInterface $configuration, AttributeMana public function getRule(string $ruleName, $user, $resource): array { if (!isset($this->rules[$ruleName])) { - throw new \InvalidArgumentException('The given rule "' . $ruleName . '" is not configured'); + throw new InvalidArgumentException('The given rule "' . $ruleName . '" is not configured'); } // TODO check if this is really useful From 05c417e741ce709690093c2b306ab93d449ef26b Mon Sep 17 00:00:00 2001 From: kievan Date: Tue, 23 Jul 2019 16:03:09 +0300 Subject: [PATCH 3/4] increase php, phpunit versions to fix tests (breaking changes) --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index da088a6..3eef2f6 100644 --- a/composer.json +++ b/composer.json @@ -13,10 +13,10 @@ } ], "require": { - "php": ">=7.0", + "php": ">=7.1", "psr/cache": "~1.0", "symfony/config": "~3.0|^4.0", - "symfony/yaml" : "~3.0|^4.0", + "symfony/yaml" : "~3.0|^4.0", "friendsofphp/php-cs-fixer": "^2.12" }, "support": { @@ -30,6 +30,6 @@ } }, "require-dev": { - "phpunit/phpunit": "^6.5" + "phpunit/phpunit": "^7.0" } } From 2110ea0096166b694633f30a4abddab224adb6b7 Mon Sep 17 00:00:00 2001 From: kievan Date: Tue, 23 Jul 2019 16:08:34 +0300 Subject: [PATCH 4/4] fix tests as per php >= 7.1 spec --- tests/AbacTest.php | 2 +- tests/Cache/Item/MemoryCacheItemTest.php | 2 +- tests/Cache/Item/TextCacheItemTest.php | 2 +- tests/Cache/Pool/MemoryCacheItemPoolTest.php | 2 +- tests/Cache/Pool/TextCacheItemPoolTest.php | 4 ++-- tests/Comparison/ArrayComparisonTest.php | 2 +- tests/Comparison/BooleanComparisonTest.php | 2 +- tests/Comparison/DatetimeComparisonTest.php | 2 +- tests/Comparison/NumericComparisonTest.php | 2 +- tests/Comparison/ObjectComparisonTest.php | 2 +- tests/Comparison/StringComparisonTest.php | 2 +- tests/Comparison/UserComparisonTest.php | 2 +- tests/Manager/AttributeManagerTest.php | 2 +- tests/Manager/CacheManagerTest.php | 2 +- tests/Manager/ComparisonManagerTest.php | 2 +- tests/Manager/PolicyRuleManagerTest.php | 2 +- 16 files changed, 17 insertions(+), 17 deletions(-) diff --git a/tests/AbacTest.php b/tests/AbacTest.php index 6d77cad..cefe686 100644 --- a/tests/AbacTest.php +++ b/tests/AbacTest.php @@ -14,7 +14,7 @@ class AbacTest extends \PHPUnit\Framework\TestCase /** @var array **/ protected $importSet; - public function setUp() + public function setUp(): void { $this->basicSet = [ AbacFactory::getAbac([__DIR__ . '/fixtures/policy_rules.yml']), diff --git a/tests/Cache/Item/MemoryCacheItemTest.php b/tests/Cache/Item/MemoryCacheItemTest.php index 6095036..8f811ca 100644 --- a/tests/Cache/Item/MemoryCacheItemTest.php +++ b/tests/Cache/Item/MemoryCacheItemTest.php @@ -9,7 +9,7 @@ class MemoryCacheItemTest extends \PHPUnit\Framework\TestCase /** @var MemoryCacheItem **/ protected $item; - public function setUp() + public function setUp(): void { $this->item = new MemoryCacheItem('php_abac.test'); } diff --git a/tests/Cache/Item/TextCacheItemTest.php b/tests/Cache/Item/TextCacheItemTest.php index 45cc6d8..21c85dc 100644 --- a/tests/Cache/Item/TextCacheItemTest.php +++ b/tests/Cache/Item/TextCacheItemTest.php @@ -9,7 +9,7 @@ class TextCacheItemTest extends \PHPUnit\Framework\TestCase /** @var TextCacheItem **/ protected $item; - public function setUp() + public function setUp(): void { $this->item = new TextCacheItem('php_abac.test'); } diff --git a/tests/Cache/Pool/MemoryCacheItemPoolTest.php b/tests/Cache/Pool/MemoryCacheItemPoolTest.php index 90c8777..8410ae0 100644 --- a/tests/Cache/Pool/MemoryCacheItemPoolTest.php +++ b/tests/Cache/Pool/MemoryCacheItemPoolTest.php @@ -9,7 +9,7 @@ class MemoryCacheItemPoolTest extends \PHPUnit\Framework\TestCase { protected $pool; - public function setUp() + public function setUp(): void { $this->pool = new MemoryCacheItemPool(); } diff --git a/tests/Cache/Pool/TextCacheItemPoolTest.php b/tests/Cache/Pool/TextCacheItemPoolTest.php index ac4b8d8..1b1ce69 100644 --- a/tests/Cache/Pool/TextCacheItemPoolTest.php +++ b/tests/Cache/Pool/TextCacheItemPoolTest.php @@ -9,14 +9,14 @@ class TextCacheItemPoolTest extends \PHPUnit\Framework\TestCase { protected $pool; - public function setUp() + public function setUp(): void { $this->pool = new TextCacheItemPool([ 'cache_folder' => __DIR__ . '/../../../data/cache/test' ]); } - public function tearDown() + public function tearDown(): void { $this->pool->clear(); } diff --git a/tests/Comparison/ArrayComparisonTest.php b/tests/Comparison/ArrayComparisonTest.php index 0bd728b..c2891d1 100644 --- a/tests/Comparison/ArrayComparisonTest.php +++ b/tests/Comparison/ArrayComparisonTest.php @@ -18,7 +18,7 @@ class ArrayComparisonTest extends \PHPUnit\Framework\TestCase /** @var ArrayComparison **/ protected $comparison; - public function setUp() + public function setUp(): void { $this->comparison = new ArrayComparison($this->getComparisonManagerMock()); } diff --git a/tests/Comparison/BooleanComparisonTest.php b/tests/Comparison/BooleanComparisonTest.php index ad4f045..f660f70 100644 --- a/tests/Comparison/BooleanComparisonTest.php +++ b/tests/Comparison/BooleanComparisonTest.php @@ -11,7 +11,7 @@ class BooleanComparisonTest extends \PHPUnit\Framework\TestCase /** @var BooleanComparison **/ protected $comparison; - public function setUp() + public function setUp(): void { $this->comparison = new BooleanComparison($this->getComparisonManagerMock()); } diff --git a/tests/Comparison/DatetimeComparisonTest.php b/tests/Comparison/DatetimeComparisonTest.php index 54c795a..8c073df 100644 --- a/tests/Comparison/DatetimeComparisonTest.php +++ b/tests/Comparison/DatetimeComparisonTest.php @@ -11,7 +11,7 @@ class DattimeeComparisonTest extends \PHPUnit\Framework\TestCase /** @var DateComparison **/ protected $comparison; - public function setUp() + public function setUp(): void { $this->comparison = new DatetimeComparison($this->getComparisonManagerMock()); } diff --git a/tests/Comparison/NumericComparisonTest.php b/tests/Comparison/NumericComparisonTest.php index 20dcb12..476a463 100644 --- a/tests/Comparison/NumericComparisonTest.php +++ b/tests/Comparison/NumericComparisonTest.php @@ -11,7 +11,7 @@ class NumericComparisonTest extends \PHPUnit\Framework\TestCase /** @var NumericComparison **/ protected $comparison; - public function setUp() + public function setUp(): void { $this->comparison = new NumericComparison($this->getComparisonManagerMock()); } diff --git a/tests/Comparison/ObjectComparisonTest.php b/tests/Comparison/ObjectComparisonTest.php index 8c5c004..730ebdf 100644 --- a/tests/Comparison/ObjectComparisonTest.php +++ b/tests/Comparison/ObjectComparisonTest.php @@ -19,7 +19,7 @@ class ObjectComparisonTest extends \PHPUnit\Framework\TestCase /** @var ArrayComparison **/ protected $comparison; - public function setUp() + public function setUp(): void { $this->comparison = new ObjectComparison($this->getComparisonManagerMock()); } diff --git a/tests/Comparison/StringComparisonTest.php b/tests/Comparison/StringComparisonTest.php index b7f8c4c..44fd45b 100644 --- a/tests/Comparison/StringComparisonTest.php +++ b/tests/Comparison/StringComparisonTest.php @@ -11,7 +11,7 @@ class StringComparisonTest extends \PHPUnit\Framework\TestCase /** @var StringComparison **/ protected $comparison; - public function setUp() + public function setUp(): void { $this->comparison = new StringComparison($this->getComparisonManagerMock()); } diff --git a/tests/Comparison/UserComparisonTest.php b/tests/Comparison/UserComparisonTest.php index f3820de..c0f1e5f 100644 --- a/tests/Comparison/UserComparisonTest.php +++ b/tests/Comparison/UserComparisonTest.php @@ -17,7 +17,7 @@ class UserComparisonTest extends \PHPUnit\Framework\TestCase /** @var ArrayComparison **/ protected $comparison; - public function setUp() + public function setUp(): void { $this->comparison = new UserComparison($this->getComparisonManagerMock()); } diff --git a/tests/Manager/AttributeManagerTest.php b/tests/Manager/AttributeManagerTest.php index d2c27bd..9645382 100644 --- a/tests/Manager/AttributeManagerTest.php +++ b/tests/Manager/AttributeManagerTest.php @@ -16,7 +16,7 @@ class AttributeManagerTest extends \PHPUnit\Framework\TestCase /** @var AttributeManager **/ private $manager; - public function setUp() + public function setUp(): void { $this->manager = new AttributeManager($this->getConfigurationMock()); } diff --git a/tests/Manager/CacheManagerTest.php b/tests/Manager/CacheManagerTest.php index f52ccd2..81fb823 100644 --- a/tests/Manager/CacheManagerTest.php +++ b/tests/Manager/CacheManagerTest.php @@ -14,7 +14,7 @@ class CacheManagerTest extends \PHPUnit\Framework\TestCase /** @var CacheManager **/ protected $cacheManager; - public function setUp() + public function setUp(): void { $this->cacheManager = new CacheManager(); } diff --git a/tests/Manager/ComparisonManagerTest.php b/tests/Manager/ComparisonManagerTest.php index 0ca8380..db06966 100644 --- a/tests/Manager/ComparisonManagerTest.php +++ b/tests/Manager/ComparisonManagerTest.php @@ -16,7 +16,7 @@ class ComparisonManagerTest extends \PHPUnit\Framework\TestCase /** @var ComparisonManager **/ protected $manager; - public function setUp() + public function setUp(): void { $this->manager = new ComparisonManager($this->getAttributeManagerMock()); } diff --git a/tests/Manager/PolicyRuleManagerTest.php b/tests/Manager/PolicyRuleManagerTest.php index bdf742f..88dafe7 100644 --- a/tests/Manager/PolicyRuleManagerTest.php +++ b/tests/Manager/PolicyRuleManagerTest.php @@ -19,7 +19,7 @@ class PolicyRuleManagerTest extends \PHPUnit\Framework\TestCase /** @var PolicyRuleManager **/ private $manager; - public function setUp() + public function setUp(): void { $this->manager = new PolicyRuleManager( $this->getConfigurationMock(),