diff --git a/.laminas-ci.json b/.laminas-ci.json
index 89ee608..6f96f6d 100644
--- a/.laminas-ci.json
+++ b/.laminas-ci.json
@@ -1,5 +1,5 @@
{
"ignore_php_platform_requirements": {
- "8.2": true
+ "8.2": false
}
-}
\ No newline at end of file
+}
diff --git a/README.md b/README.md
index b2fab29..66820b8 100644
--- a/README.md
+++ b/README.md
@@ -1,21 +1,22 @@
# mezzio-authorization-rbac
[![Build Status](https://github.com/mezzio/mezzio-authorization-rbac/workflows/Continuous%20Integration/badge.svg)](https://github.com/mezzio/mezzio-authorization-rbac/actions?query=workflow%3A"Continuous+Integration")
+[![Type Coverage](https://shepherd.dev/github/mezzio/mezzio-authorization-rbac/coverage.svg)](https://shepherd.dev/github/mezzio/mezzio-authorization-rbac)
> ## π·πΊ Π ΡΡΡΠΊΠΈΠΌ Π³ΡΠ°ΠΆΠ΄Π°Π½Π°ΠΌ
->
+>
> ΠΡ, ΡΡΠ°ΡΡΠ½ΠΈΠΊΠΈ Laminas, ΡΠΎΠ΄ΠΈΠ»ΠΈΡΡ ΠΈ ΠΆΠΈΠ²Π΅ΠΌ Π² ΡΠ°Π·Π½ΡΡ
ΡΡΡΠ°Π½Π°Ρ
. Π£ ΠΌΠ½ΠΎΠ³ΠΈΡ
ΠΈΠ· Π½Π°Ρ Π΅ΡΡΡ Π΄ΡΡΠ·ΡΡ, ΡΠΎΠ΄ΡΡΠ²Π΅Π½Π½ΠΈΠΊΠΈ ΠΈ ΠΊΠΎΠ»Π»Π΅Π³ΠΈ ΠΊΠ°ΠΊ Π² Π ΠΎΡΡΠΈΠΈ, ΡΠ°ΠΊ ΠΈ Π² Π£ΠΊΡΠ°ΠΈΠ½Π΅. ΠΠ΅ΠΊΠΎΡΠΎΡΡΠ΅ ΠΈΠ· Π½Π°Ρ ΡΠΎΠ΄ΠΈΠ»ΠΈΡΡ Π² Π ΠΎΡΡΠΈΠΈ. ΠΠ΅ΠΊΠΎΡΠΎΡΡΠ΅ ΠΈΠ· Π½Π°Ρ ΠΆΠΈΠ²ΡΡ Π² Π ΠΎΡΡΠΈΠΈ. Π£ Π½Π΅ΠΊΠΎΡΠΎΡΡΡ
Π±Π°Π±ΡΡΠΊΠΈ ΠΈ Π΄Π΅Π΄ΡΡΠΊΠΈ ΡΡΠ°ΠΆΠ°Π»ΠΈΡΡ Ρ ΡΠ°ΡΠΈΡΡΠ°ΠΌΠΈ Π²ΠΎ ΠΡΠΎΡΠΎΠΉ ΠΌΠΈΡΠΎΠ²ΠΎΠΉ Π²ΠΎΠΉΠ½Π΅. ΠΠ΄Π΅ΡΡ Π½ΠΈΠΊΡΠΎ Π½Π΅ ΠΏΠΎΠ΄Π΄Π΅ΡΠΆΠΈΠ²Π°Π΅Ρ ΡΠ°ΡΠΈΠ·ΠΌ.
->
+>
> Π£ ΠΎΠ΄Π½ΠΎΠ³ΠΎ ΠΈΠ· Π½Π°Ρ Π΅ΡΡΡ ΡΠΊΡΠ°ΠΈΠ½ΡΠΊΠ°Ρ ΡΠΎΠ΄ΡΡΠ²Π΅Π½Π½ΠΈΡΠ°, ΠΊΠΎΡΠΎΡΠ°Ρ ΡΠΏΠ°ΡΠ»Π°ΡΡ ΠΈΠ· Π΄ΠΎΠΌΠ° Π²ΠΌΠ΅ΡΡΠ΅ Ρ ΡΡΠ½ΠΎΠΌ. ΠΠΎΠ΅Π·Π΄ Π·Π°Π΄Π΅ΡΠΆΠ°Π»ΡΡ ΠΈΠ·-Π·Π° Π±ΠΎΠΌΠ±Π΅ΠΆΠΊΠΈ Π½Π° Π΄ΠΎΡΠΎΠ³Π΅ Π²ΠΏΠ΅ΡΠ΅Π΄ΠΈ. Π£ Π½Π°Ρ Π΅ΡΡΡ Π΄ΡΡΠ·ΡΡ, ΠΊΠΎΡΠΎΡΡΠ΅ ΠΏΡΡΡΡΡΡΡ Π² Π±ΠΎΠΌΠ±ΠΎΡΠ±Π΅ΠΆΠΈΡΠ°Ρ
. ΠΡ Ρ ΡΡΠ΅Π²ΠΎΠ³ΠΎΠΉ ΠΆΠ΄Π΅ΠΌ Π²Π΅ΡΡΠΎΡΠΊΠΈ ΠΎΡ Π½ΠΈΡ
ΠΏΠΎΡΠ»Π΅ Π²ΠΎΠ·Π΄ΡΡΠ½ΡΡ
Π½Π°Π»Π΅ΡΠΎΠ², ΠΊΠΎΡΠΎΡΡΠ΅ Π±Π΅ΡΠΏΠΎΡΡΠ΄ΠΎΡΠ½ΠΎ Π½Π°Π½ΠΎΡΡΡ ΡΠ΄Π°ΡΡ ΠΈ ΠΏΠΎΠΏΠ°Π΄Π°ΡΡ ΠΏΠΎ Π±ΠΎΠ»ΡΠ½ΠΈΡΠ°ΠΌ, ΡΠΊΠΎΠ»Π°ΠΌ, Π΄Π΅ΡΡΠΊΠΈΠΌ ΡΠ°Π΄Π°ΠΌ ΠΈ Π΄ΠΎΠΌΠ°ΠΌ. ΠΡ Π½Π΅ Π±Π΅ΡΠ΅ΠΌ ΡΡΠΎ ΠΈΠ· ΠΊΠ°ΠΊΠΈΡ
-Π»ΠΈΠ±ΠΎ Π‘ΠΠ. ΠΡ Π½Π°Π±Π»ΡΠ΄Π°Π΅ΠΌ ΡΡΠΎ Π½Π°ΠΏΡΡΠΌΡΡ.
->
+>
> ΠΡ Π΄ΠΎΠ²Π΅ΡΡΠ΅ΡΠ΅ Π½Π°ΠΌ Π΄ΠΎΡΡΠ°ΡΠΎΡΠ½ΠΎ, ΡΡΠΎΠ± ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΡ Π½Π°ΡΠΈ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΡ, ΠΈ ΠΌΡ ΠΏΡΠΎΡΠΈΠΌ Π²Π°Ρ Π΄ΠΎΠ²Π΅ΡΠΈΡΡΡΡ Π½Π°ΠΌ Π²Π½ΠΎΠ²Ρ. ΠΡ Π½ΡΠΆΠ΄Π°Π΅ΠΌΡΡ Π² ΠΏΠΎΠΌΠΎΡΠΈ. ΠΡΡ
ΠΎΠ΄ΠΈΡΠ΅ ΠΈ ΠΏΡΠΎΡΠ΅ΡΡΡΠΉΡΠ΅ ΠΏΡΠΎΡΠΈΠ² ΡΡΠΎΠΉ Π±Π΅ΡΠΏΠΎΠ»Π΅Π·Π½ΠΎΠΉ Π²ΠΎΠΉΠ½Ρ. ΠΡΡΠ°Π½ΠΎΠ²ΠΈΡΠ΅ ΠΊΡΠΎΠ²ΠΎΠΏΡΠΎΠ»ΠΈΡΠΈΠ΅. Π‘ΠΊΠ°ΠΆΠΈΡΠ΅ "ΠΠ΅Ρ Π²ΠΎΠΉΠ½Π΅!"
->
+>
> ## πΊπΈ To Citizens of Russia
->
+>
> We at Laminas come from all over the world. Many of us have friends, family and colleagues in both Russia and Ukraine. Some of us were born in Russia. Some of us currently live in Russia. Some have grandparents who fought Nazis in World War II. Nobody here supports fascism.
->
+>
> One team member has a Ukrainian relative who fled her home with her son. The train was delayed due to bombing on the road ahead. We have friends who are hiding in bomb shelters. We anxiously follow up on them after the air raids, which indiscriminately fire at hospitals, schools, kindergartens and houses. We're not taking this from any media. These are our actual experiences.
->
+>
> You trust us enough to use our software. We ask that you trust us to say the truth on this. We need your help. Go out and protest this unnecessary war. Stop the bloodshed. Say "stop the war!"
[![Coverage Status](https://coveralls.io/repos/github/mezzio/mezzio-authorization-rbac/badge.svg?branch=master)](https://coveralls.io/github/mezzio/mezzio-authorization-rbac?branch=master)
diff --git a/composer.json b/composer.json
index 647eb47..511e307 100644
--- a/composer.json
+++ b/composer.json
@@ -43,12 +43,10 @@
},
"require-dev": {
"laminas/laminas-coding-standard": "~2.5.0",
- "laminas/laminas-servicemanager": "^3.10",
- "phpspec/prophecy": "^1.15",
- "phpspec/prophecy-phpunit": "^2.0.1",
- "phpunit/phpunit": "^9.5.26",
- "psalm/plugin-phpunit": "^0.18.0",
- "vimeo/psalm": "^5.0.0"
+ "laminas/laminas-servicemanager": "^3.20",
+ "phpunit/phpunit": "^9.5.28",
+ "psalm/plugin-phpunit": "^0.18.4",
+ "vimeo/psalm": "^5.4"
},
"conflict": {
"container-interop/container-interop": "<1.2.0",
diff --git a/composer.lock b/composer.lock
index c95e371..f6f954a 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "12f604fc7a99740ef78d40af1f804664",
+ "content-hash": "dbeb71804f1d8081f1a56b0a3327ffcd",
"packages": [
{
"name": "fig/http-message-util",
@@ -280,16 +280,16 @@
},
{
"name": "mezzio/mezzio-router",
- "version": "3.10.0",
+ "version": "3.13.0",
"source": {
"type": "git",
"url": "https://github.com/mezzio/mezzio-router.git",
- "reference": "f98d3e97b0e949d394703e526bf218402be601bf"
+ "reference": "cb9e2476844074587e1ed849f53ef466a7e8d893"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/mezzio/mezzio-router/zipball/f98d3e97b0e949d394703e526bf218402be601bf",
- "reference": "f98d3e97b0e949d394703e526bf218402be601bf",
+ "url": "https://api.github.com/repos/mezzio/mezzio-router/zipball/cb9e2476844074587e1ed849f53ef466a7e8d893",
+ "reference": "cb9e2476844074587e1ed849f53ef466a7e8d893",
"shasum": ""
},
"require": {
@@ -306,12 +306,12 @@
"zendframework/zend-expressive-router": "*"
},
"require-dev": {
- "laminas/laminas-coding-standard": "~2.4.0",
- "laminas/laminas-diactoros": "^2.20.0",
+ "laminas/laminas-coding-standard": "~2.5.0",
+ "laminas/laminas-diactoros": "^2.24",
"laminas/laminas-stratigility": "^3.9.0",
- "phpunit/phpunit": "^9.5.26",
- "psalm/plugin-phpunit": "^0.18.0",
- "vimeo/psalm": "^5.0.0"
+ "phpunit/phpunit": "^9.5.27",
+ "psalm/plugin-phpunit": "^0.18.4",
+ "vimeo/psalm": "^5.4"
},
"suggest": {
"mezzio/mezzio-aurarouter": "^3.0 to use the Aura.Router routing adapter",
@@ -357,7 +357,7 @@
"type": "community_bridge"
}
],
- "time": "2022-12-13T20:50:07+00:00"
+ "time": "2023-01-15T08:25:11+00:00"
},
{
"name": "psr/container",
@@ -2137,125 +2137,6 @@
},
"time": "2022-10-14T12:47:21+00:00"
},
- {
- "name": "phpspec/prophecy",
- "version": "v1.16.0",
- "source": {
- "type": "git",
- "url": "https://github.com/phpspec/prophecy.git",
- "reference": "be8cac52a0827776ff9ccda8c381ac5b71aeb359"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/phpspec/prophecy/zipball/be8cac52a0827776ff9ccda8c381ac5b71aeb359",
- "reference": "be8cac52a0827776ff9ccda8c381ac5b71aeb359",
- "shasum": ""
- },
- "require": {
- "doctrine/instantiator": "^1.2",
- "php": "^7.2 || 8.0.* || 8.1.* || 8.2.*",
- "phpdocumentor/reflection-docblock": "^5.2",
- "sebastian/comparator": "^3.0 || ^4.0",
- "sebastian/recursion-context": "^3.0 || ^4.0"
- },
- "require-dev": {
- "phpspec/phpspec": "^6.0 || ^7.0",
- "phpunit/phpunit": "^8.0 || ^9.0"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "1.x-dev"
- }
- },
- "autoload": {
- "psr-4": {
- "Prophecy\\": "src/Prophecy"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Konstantin Kudryashov",
- "email": "ever.zet@gmail.com",
- "homepage": "http://everzet.com"
- },
- {
- "name": "Marcello Duarte",
- "email": "marcello.duarte@gmail.com"
- }
- ],
- "description": "Highly opinionated mocking framework for PHP 5.3+",
- "homepage": "https://github.com/phpspec/prophecy",
- "keywords": [
- "Double",
- "Dummy",
- "fake",
- "mock",
- "spy",
- "stub"
- ],
- "support": {
- "issues": "https://github.com/phpspec/prophecy/issues",
- "source": "https://github.com/phpspec/prophecy/tree/v1.16.0"
- },
- "time": "2022-11-29T15:06:56+00:00"
- },
- {
- "name": "phpspec/prophecy-phpunit",
- "version": "v2.0.1",
- "source": {
- "type": "git",
- "url": "https://github.com/phpspec/prophecy-phpunit.git",
- "reference": "2d7a9df55f257d2cba9b1d0c0963a54960657177"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/phpspec/prophecy-phpunit/zipball/2d7a9df55f257d2cba9b1d0c0963a54960657177",
- "reference": "2d7a9df55f257d2cba9b1d0c0963a54960657177",
- "shasum": ""
- },
- "require": {
- "php": "^7.3 || ^8",
- "phpspec/prophecy": "^1.3",
- "phpunit/phpunit": "^9.1"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "2.0-dev"
- }
- },
- "autoload": {
- "psr-4": {
- "Prophecy\\PhpUnit\\": "src"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Christophe Coevoet",
- "email": "stof@notk.org"
- }
- ],
- "description": "Integrating the Prophecy mocking library in PHPUnit test cases",
- "homepage": "http://phpspec.net",
- "keywords": [
- "phpunit",
- "prophecy"
- ],
- "support": {
- "issues": "https://github.com/phpspec/prophecy-phpunit/issues",
- "source": "https://github.com/phpspec/prophecy-phpunit/tree/v2.0.1"
- },
- "time": "2020-07-09T08:33:42+00:00"
- },
{
"name": "phpstan/phpdoc-parser",
"version": "1.5.1",
@@ -2620,20 +2501,20 @@
},
{
"name": "phpunit/phpunit",
- "version": "9.5.27",
+ "version": "9.5.28",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
- "reference": "a2bc7ffdca99f92d959b3f2270529334030bba38"
+ "reference": "954ca3113a03bf780d22f07bf055d883ee04b65e"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a2bc7ffdca99f92d959b3f2270529334030bba38",
- "reference": "a2bc7ffdca99f92d959b3f2270529334030bba38",
+ "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/954ca3113a03bf780d22f07bf055d883ee04b65e",
+ "reference": "954ca3113a03bf780d22f07bf055d883ee04b65e",
"shasum": ""
},
"require": {
- "doctrine/instantiator": "^1.3.1",
+ "doctrine/instantiator": "^1.3.1 || ^2",
"ext-dom": "*",
"ext-json": "*",
"ext-libxml": "*",
@@ -2702,7 +2583,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
- "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.27"
+ "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.28"
},
"funding": [
{
@@ -2718,7 +2599,7 @@
"type": "tidelift"
}
],
- "time": "2022-12-09T07:31:23+00:00"
+ "time": "2023-01-14T12:32:24+00:00"
},
{
"name": "psalm/plugin-phpunit",
diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index c5d3aaf..f75af81 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -54,118 +54,4 @@
new $package['extra']['laminas']['config-provider']()
-
-
- testFactoryWithAssertion
- testFactoryWithEmptyRolesPermissionsWithAssertion
- testFactoryWithEmptyRolesPermissionsWithoutAssertion
- testFactoryWithInvalidRole
- testFactoryWithUnknownRole
- testFactoryWithoutAssertion
- testFactoryWithoutConfig
- testFactoryWithoutLaminasRbacConfig
- testFactoryWithoutPermissions
-
-
- $this->container->reveal()
- $this->container->reveal()
- $this->container->reveal()
- $this->container->reveal()
- $this->container->reveal()
- $this->container->reveal()
- $this->container->reveal()
- $this->container->reveal()
- $this->container->reveal()
-
-
- willReturn
- willReturn
- willReturn
- willReturn
- willReturn
- willReturn
- willReturn
- willReturn
- willReturn
- willReturn
- willReturn
-
-
- willReturn
- willReturn
- willReturn
- willReturn
- willReturn
- willReturn
- willReturn
- willReturn
- willReturn
- willReturn
-
-
- reveal
- reveal
- reveal
- reveal
- reveal
- reveal
- reveal
- reveal
- reveal
-
-
-
-
- testConstructorWithAssertion
- testConstructorWithoutAssertion
- testIsGrantedWitAssertion
- testIsGrantedWithFailedRouting
- testIsGrantedWithoutAssertion
- testIsGrantedWithoutRouteResult
- testIsNotGrantedWitAssertion
- testIsNotGrantedWithoutAssertion
-
-
- $this->assertion->reveal()
- $this->assertion->reveal()
- $this->assertion->reveal()
- $this->assertion->reveal()
- $this->assertion->reveal()
- $this->assertion->reveal()
- $this->rbac->reveal()
- $this->rbac->reveal()
- $this->rbac->reveal()
- $this->rbac->reveal()
- $this->rbac->reveal()
- $this->rbac->reveal()
- $this->rbac->reveal()
- $this->rbac->reveal()
-
-
- willReturn
- willReturn
- willReturn
- willReturn
-
-
- shouldBeCalled
- shouldBeCalled
-
-
- reveal
- reveal
- reveal
- reveal
- reveal
- reveal
- reveal
- reveal
- reveal
- reveal
- reveal
- reveal
- reveal
- reveal
-
-
diff --git a/test/LaminasRbacFactoryTest.php b/test/LaminasRbacFactoryTest.php
index 9270a7b..db0a0c5 100644
--- a/test/LaminasRbacFactoryTest.php
+++ b/test/LaminasRbacFactoryTest.php
@@ -8,49 +8,45 @@
use Mezzio\Authorization\Rbac\LaminasRbac;
use Mezzio\Authorization\Rbac\LaminasRbacAssertionInterface;
use Mezzio\Authorization\Rbac\LaminasRbacFactory;
+use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-use Prophecy\PhpUnit\ProphecyTrait;
-use Prophecy\Prophecy\ObjectProphecy;
use Psr\Container\ContainerInterface;
-use Zend\Expressive\Authorization\Rbac\ZendRbacAssertionInterface;
class LaminasRbacFactoryTest extends TestCase
{
- use ProphecyTrait;
-
- /** @var ContainerInterface|ObjectProphecy */
- private $container;
+ /** @var ContainerInterface&MockObject */
+ private ContainerInterface $container;
protected function setUp(): void
{
- $this->container = $this->prophesize(ContainerInterface::class);
+ $this->container = $this->createMock(ContainerInterface::class);
}
- public function testFactoryWithoutConfig()
+ public function testFactoryWithoutConfig(): void
{
- $this->container->get('config')->willReturn([]);
+ $this->container->method('get')->with('config')->willReturn([]);
$factory = new LaminasRbacFactory();
$this->expectException(Exception\InvalidConfigException::class);
$this->expectExceptionMessage('mezzio-authorization-rbac');
- $factory($this->container->reveal());
+ $factory($this->container);
}
- public function testFactoryWithoutLaminasRbacConfig()
+ public function testFactoryWithoutLaminasRbacConfig(): void
{
- $this->container->get('config')->willReturn(['mezzio-authorization-rbac' => []]);
+ $this->container->method('get')->with('config')->willReturn(['mezzio-authorization-rbac' => []]);
$factory = new LaminasRbacFactory();
$this->expectException(Exception\InvalidConfigException::class);
$this->expectExceptionMessage('mezzio-authorization-rbac.roles');
- $factory($this->container->reveal());
+ $factory($this->container);
}
- public function testFactoryWithoutPermissions()
+ public function testFactoryWithoutPermissions(): void
{
- $this->container->get('config')->willReturn([
+ $this->container->method('get')->with('config')->willReturn([
'mezzio-authorization-rbac' => [
'roles' => [],
],
@@ -60,46 +56,55 @@ public function testFactoryWithoutPermissions()
$this->expectException(Exception\InvalidConfigException::class);
$this->expectExceptionMessage('mezzio-authorization-rbac.permissions');
- $factory($this->container->reveal());
+ $factory($this->container);
}
- public function testFactoryWithEmptyRolesPermissionsWithoutAssertion()
+ public function testFactoryWithEmptyRolesPermissionsWithoutAssertion(): void
{
- $this->container->get('config')->willReturn([
+ $this->container->method('get')->with('config')->willReturn([
'mezzio-authorization-rbac' => [
'roles' => [],
'permissions' => [],
],
]);
- $this->container->has(LaminasRbacAssertionInterface::class)->willReturn(false);
- $this->container->has(ZendRbacAssertionInterface::class)->willReturn(false);
+
+ $this->container->method('has')
+ ->withConsecutive(
+ [LaminasRbacAssertionInterface::class],
+ ['Zend\Expressive\Authorization\Rbac\ZendRbacAssertionInterface']
+ )->willReturn(false, false);
$factory = new LaminasRbacFactory();
- $laminasRbac = $factory($this->container->reveal());
- $this->assertInstanceOf(LaminasRbac::class, $laminasRbac);
+ $laminasRbac = $factory($this->container);
+ self::assertInstanceOf(LaminasRbac::class, $laminasRbac);
}
- public function testFactoryWithEmptyRolesPermissionsWithAssertion()
+ public function testFactoryWithEmptyRolesPermissionsWithAssertion(): void
{
- $this->container->get('config')->willReturn([
+ $assertion = $this->createMock(LaminasRbacAssertionInterface::class);
+ $config = [
'mezzio-authorization-rbac' => [
'roles' => [],
'permissions' => [],
],
- ]);
+ ];
- $assertion = $this->prophesize(LaminasRbacAssertionInterface::class);
- $this->container->has(LaminasRbacAssertionInterface::class)->willReturn(true);
- $this->container->get(LaminasRbacAssertionInterface::class)->willReturn($assertion->reveal());
+ $this->container->method('get')
+ ->willReturnMap([
+ ['config', $config],
+ [LaminasRbacAssertionInterface::class, $assertion],
+ ]);
+
+ $this->container->method('has')->with(LaminasRbacAssertionInterface::class)->willReturn(true);
$factory = new LaminasRbacFactory();
- $laminasRbac = $factory($this->container->reveal());
- $this->assertInstanceOf(LaminasRbac::class, $laminasRbac);
+ $laminasRbac = $factory($this->container);
+ self::assertInstanceOf(LaminasRbac::class, $laminasRbac);
}
- public function testFactoryWithoutAssertion()
+ public function testFactoryWithoutAssertion(): void
{
- $this->container->get('config')->willReturn([
+ $config = [
'mezzio-authorization-rbac' => [
'roles' => [
'administrator' => [],
@@ -119,18 +124,22 @@ public function testFactoryWithoutAssertion()
],
],
],
- ]);
- $this->container->has(LaminasRbacAssertionInterface::class)->willReturn(false);
- $this->container->has(ZendRbacAssertionInterface::class)->willReturn(false);
+ ];
+ $this->container->method('get')->with('config')->willReturn($config);
+ $this->container->method('has')
+ ->withConsecutive(
+ [LaminasRbacAssertionInterface::class],
+ ['Zend\Expressive\Authorization\Rbac\ZendRbacAssertionInterface'],
+ )->willReturn(false, false);
$factory = new LaminasRbacFactory();
- $laminasRbac = $factory($this->container->reveal());
- $this->assertInstanceOf(LaminasRbac::class, $laminasRbac);
+ $laminasRbac = $factory($this->container);
+ self::assertInstanceOf(LaminasRbac::class, $laminasRbac);
}
- public function testFactoryWithAssertion()
+ public function testFactoryWithAssertion(): void
{
- $this->container->get('config')->willReturn([
+ $config = [
'mezzio-authorization-rbac' => [
'roles' => [
'administrator' => [],
@@ -150,19 +159,25 @@ public function testFactoryWithAssertion()
],
],
],
- ]);
- $assertion = $this->prophesize(LaminasRbacAssertionInterface::class);
- $this->container->has(LaminasRbacAssertionInterface::class)->willReturn(true);
- $this->container->get(LaminasRbacAssertionInterface::class)->willReturn($assertion->reveal());
+ ];
+ $assertion = $this->createMock(LaminasRbacAssertionInterface::class);
+
+ $this->container->method('has')->with(LaminasRbacAssertionInterface::class)->willReturn(true);
+
+ $this->container->method('get')
+ ->willReturnMap([
+ ['config', $config],
+ [LaminasRbacAssertionInterface::class, $assertion],
+ ]);
$factory = new LaminasRbacFactory();
- $laminasRbac = $factory($this->container->reveal());
- $this->assertInstanceOf(LaminasRbac::class, $laminasRbac);
+ $laminasRbac = $factory($this->container);
+ self::assertInstanceOf(LaminasRbac::class, $laminasRbac);
}
- public function testFactoryWithInvalidRole()
+ public function testFactoryWithInvalidRole(): void
{
- $this->container->get('config')->willReturn([
+ $this->container->method('get')->with('config')->willReturn([
'mezzio-authorization-rbac' => [
'roles' => [
1 => [],
@@ -170,18 +185,22 @@ public function testFactoryWithInvalidRole()
'permissions' => [],
],
]);
- $this->container->has(LaminasRbacAssertionInterface::class)->willReturn(false);
- $this->container->has(ZendRbacAssertionInterface::class)->willReturn(false);
+
+ $this->container->method('has')
+ ->withConsecutive([
+ LaminasRbacAssertionInterface::class,
+ 'Zend\Expressive\Authorization\Rbac\ZendRbacAssertionInterface',
+ ])->willReturn(false, false);
$factory = new LaminasRbacFactory();
$this->expectException(Exception\InvalidConfigException::class);
- $factory($this->container->reveal());
+ $factory($this->container);
}
- public function testFactoryWithUnknownRole()
+ public function testFactoryWithUnknownRole(): void
{
- $this->container->get('config')->willReturn([
+ $this->container->method('get')->with('config')->willReturn([
'mezzio-authorization-rbac' => [
'roles' => [
'administrator' => [],
@@ -194,12 +213,15 @@ public function testFactoryWithUnknownRole()
],
],
]);
- $this->container->has(LaminasRbacAssertionInterface::class)->willReturn(false);
- $this->container->has(ZendRbacAssertionInterface::class)->willReturn(false);
+ $this->container->method('has')
+ ->withConsecutive([
+ LaminasRbacAssertionInterface::class,
+ 'Zend\Expressive\Authorization\Rbac\ZendRbacAssertionInterface',
+ ])->willReturn(false, false);
$factory = new LaminasRbacFactory();
$this->expectException(Exception\InvalidConfigException::class);
- $factory($this->container->reveal());
+ $factory($this->container);
}
}
diff --git a/test/LaminasRbacTest.php b/test/LaminasRbacTest.php
index d4d07bc..3ecf925 100644
--- a/test/LaminasRbacTest.php
+++ b/test/LaminasRbacTest.php
@@ -10,131 +10,151 @@
use Mezzio\Authorization\Rbac\LaminasRbacAssertionInterface;
use Mezzio\Router\Route;
use Mezzio\Router\RouteResult;
+use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-use Prophecy\PhpUnit\ProphecyTrait;
-use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Message\ServerRequestInterface;
class LaminasRbacTest extends TestCase
{
- use ProphecyTrait;
+ /** @var Rbac&MockObject */
+ private Rbac $rbac;
- /** @var Rbac|ObjectProphecy */
- private $rbac;
-
- /** @var LaminasRbacAssertionInterface|ObjectProphecy */
- private $assertion;
+ /** @var LaminasRbacAssertionInterface&MockObject */
+ private LaminasRbacAssertionInterface $assertion;
protected function setUp(): void
{
- $this->rbac = $this->prophesize(Rbac::class);
- $this->assertion = $this->prophesize(LaminasRbacAssertionInterface::class);
+ $this->rbac = $this->createMock(Rbac::class);
+ $this->assertion = $this->createMock(LaminasRbacAssertionInterface::class);
}
- public function testConstructorWithoutAssertion()
+ public function testConstructorWithoutAssertion(): void
{
- $laminasRbac = new LaminasRbac($this->rbac->reveal());
- $this->assertInstanceOf(LaminasRbac::class, $laminasRbac);
+ $laminasRbac = new LaminasRbac($this->rbac);
+ self::assertInstanceOf(LaminasRbac::class, $laminasRbac);
}
- public function testConstructorWithAssertion()
+ public function testConstructorWithAssertion(): void
{
- $laminasRbac = new LaminasRbac($this->rbac->reveal(), $this->assertion->reveal());
- $this->assertInstanceOf(LaminasRbac::class, $laminasRbac);
+ $laminasRbac = new LaminasRbac($this->rbac, $this->assertion);
+ self::assertInstanceOf(LaminasRbac::class, $laminasRbac);
}
- public function testIsGrantedWithoutRouteResult()
+ public function testIsGrantedWithoutRouteResult(): void
{
- $laminasRbac = new LaminasRbac($this->rbac->reveal(), $this->assertion->reveal());
+ $laminasRbac = new LaminasRbac($this->rbac, $this->assertion);
- $request = $this->prophesize(ServerRequestInterface::class);
- $request->getAttribute(RouteResult::class, false)->willReturn(false);
+ $request = $this->createMock(ServerRequestInterface::class);
+ $request->method('getAttribute')
+ ->with(RouteResult::class, false)
+ ->willReturn(false);
$this->expectException(Exception\RuntimeException::class);
- $laminasRbac->isGranted('foo', $request->reveal());
+ $laminasRbac->isGranted('foo', $request);
}
- public function testIsGrantedWithoutAssertion()
+ public function testIsGrantedWithoutAssertion(): void
{
- $this->rbac->isGranted('foo', 'home', null)->willReturn(true);
- $laminasRbac = new LaminasRbac($this->rbac->reveal());
+ $this->rbac->expects(self::once())
+ ->method('isGranted')
+ ->with('foo', 'home', null)
+ ->willReturn(true);
- $routeResult = $this->getSuccessRouteResult('home');
+ $laminasRbac = new LaminasRbac($this->rbac);
- $request = $this->prophesize(ServerRequestInterface::class);
- $request->getAttribute(RouteResult::class, false)->willReturn($routeResult);
+ $request = $this->createMock(ServerRequestInterface::class);
+ $request->method('getAttribute')
+ ->with(RouteResult::class, false)
+ ->willReturn($this->getSuccessRouteResult('home'));
- $result = $laminasRbac->isGranted('foo', $request->reveal());
- $this->assertTrue($result);
+ $result = $laminasRbac->isGranted('foo', $request);
+ self::assertTrue($result);
}
- public function testIsNotGrantedWithoutAssertion()
+ public function testIsNotGrantedWithoutAssertion(): void
{
- $this->rbac->isGranted('foo', 'home', null)->willReturn(false);
- $laminasRbac = new LaminasRbac($this->rbac->reveal());
+ $this->rbac->expects(self::once())
+ ->method('isGranted')
+ ->with('foo', 'home', null)
+ ->willReturn(false);
- $routeResult = $this->getSuccessRouteResult('home');
+ $laminasRbac = new LaminasRbac($this->rbac);
- $request = $this->prophesize(ServerRequestInterface::class);
- $request->getAttribute(RouteResult::class, false)->willReturn($routeResult);
+ $request = $this->createMock(ServerRequestInterface::class);
+ $request->method('getAttribute')
+ ->with(RouteResult::class, false)
+ ->willReturn($this->getSuccessRouteResult('home'));
- $result = $laminasRbac->isGranted('foo', $request->reveal());
- $this->assertFalse($result);
+ $result = $laminasRbac->isGranted('foo', $request);
+ self::assertFalse($result);
}
- public function testIsGrantedWitAssertion()
+ public function testIsGrantedWitAssertion(): void
{
- $routeResult = $this->getSuccessRouteResult('home');
+ $request = $this->createMock(ServerRequestInterface::class);
+ $request->method('getAttribute')
+ ->with(RouteResult::class, false)
+ ->willReturn($this->getSuccessRouteResult('home'));
- $request = $this->prophesize(ServerRequestInterface::class);
- $request->getAttribute(RouteResult::class, false)->willReturn($routeResult);
+ $this->rbac->expects(self::once())
+ ->method('isGranted')
+ ->with('foo', 'home', $this->assertion)
+ ->willReturn(true);
- $this->rbac->isGranted('foo', 'home', $this->assertion->reveal())->willReturn(true);
+ $this->assertion->expects(self::once())
+ ->method('setRequest')
+ ->with($request);
- $laminasRbac = new LaminasRbac($this->rbac->reveal(), $this->assertion->reveal());
+ $laminasRbac = new LaminasRbac($this->rbac, $this->assertion);
- $result = $laminasRbac->isGranted('foo', $request->reveal());
- $this->assertTrue($result);
- $this->assertion->setRequest($request->reveal())->shouldBeCalled();
+ $result = $laminasRbac->isGranted('foo', $request);
+ self::assertTrue($result);
}
- public function testIsNotGrantedWitAssertion()
+ public function testIsNotGrantedWitAssertion(): void
{
- $routeResult = $this->getSuccessRouteResult('home');
+ $request = $this->createMock(ServerRequestInterface::class);
+ $request->method('getAttribute')
+ ->with(RouteResult::class, false)
+ ->willReturn($this->getSuccessRouteResult('home'));
- $request = $this->prophesize(ServerRequestInterface::class);
- $request->getAttribute(RouteResult::class, false)->willReturn($routeResult);
+ $this->rbac->expects(self::once())
+ ->method('isGranted')
+ ->with('foo', 'home', $this->assertion)
+ ->willReturn(false);
- $this->rbac->isGranted('foo', 'home', $this->assertion->reveal())->willReturn(false);
+ $this->assertion->expects(self::once())
+ ->method('setRequest')
+ ->with($request);
- $laminasRbac = new LaminasRbac($this->rbac->reveal(), $this->assertion->reveal());
+ $laminasRbac = new LaminasRbac($this->rbac, $this->assertion);
- $result = $laminasRbac->isGranted('foo', $request->reveal());
- $this->assertFalse($result);
- $this->assertion->setRequest($request->reveal())->shouldBeCalled();
+ $result = $laminasRbac->isGranted('foo', $request);
+ self::assertFalse($result);
}
- public function testIsGrantedWithFailedRouting()
+ public function testIsGrantedWithFailedRouting(): void
{
- $routeResult = $this->getFailureRouteResult(Route::HTTP_METHOD_ANY);
-
- $request = $this->prophesize(ServerRequestInterface::class);
- $request->getAttribute(RouteResult::class, false)->willReturn($routeResult);
+ $request = $this->createMock(ServerRequestInterface::class);
+ $request->method('getAttribute')
+ ->with(RouteResult::class, false)
+ ->willReturn($this->getFailureRouteResult(Route::HTTP_METHOD_ANY));
- $laminasRbac = new LaminasRbac($this->rbac->reveal());
+ $laminasRbac = new LaminasRbac($this->rbac);
- $result = $laminasRbac->isGranted('foo', $request->reveal());
- $this->assertTrue($result);
+ $result = $laminasRbac->isGranted('foo', $request);
+ self::assertTrue($result);
}
private function getSuccessRouteResult(string $routeName): RouteResult
{
- $route = $this->prophesize(Route::class);
- $route->getName()->willReturn($routeName);
+ $route = $this->createMock(Route::class);
+ $route->method('getName')->willReturn($routeName);
- return RouteResult::fromRoute($route->reveal());
+ return RouteResult::fromRoute($route);
}
+ /** @param list|null $methods */
private function getFailureRouteResult(?array $methods): RouteResult
{
return RouteResult::fromRouteFailure($methods);