diff --git a/ci/qa/phpunit.xml b/ci/qa/phpunit.xml
index 8d17dbb5..0f05cc07 100644
--- a/ci/qa/phpunit.xml
+++ b/ci/qa/phpunit.xml
@@ -17,7 +17,7 @@
-
+
diff --git a/composer.json b/composer.json
index e269211f..862bbeb0 100644
--- a/composer.json
+++ b/composer.json
@@ -48,7 +48,6 @@
"khanamiryan/qrcode-detector-decoder": "^2.0",
"league/csv": "^9.13",
"malukenho/docheader": "^1",
- "mockery/mockery": "^1.6",
"overtrue/phplint": "*",
"phpmd/phpmd": "^2.15",
"phpstan/phpstan": "^1.10",
diff --git a/composer.lock b/composer.lock
index c94b49b7..dbc64042 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": "be9d520404343ee4e12d3071c5bf78e1",
+ "content-hash": "364d7351b9f4930e8d29773e7330e973",
"packages": [
{
"name": "beberlei/assert",
@@ -8400,57 +8400,6 @@
"abandoned": "guzzlehttp/guzzle",
"time": "2014-01-28T22:29:15+00:00"
},
- {
- "name": "hamcrest/hamcrest-php",
- "version": "v2.0.1",
- "source": {
- "type": "git",
- "url": "https://github.com/hamcrest/hamcrest-php.git",
- "reference": "8c3d0a3f6af734494ad8f6fbbee0ba92422859f3"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/hamcrest/hamcrest-php/zipball/8c3d0a3f6af734494ad8f6fbbee0ba92422859f3",
- "reference": "8c3d0a3f6af734494ad8f6fbbee0ba92422859f3",
- "shasum": ""
- },
- "require": {
- "php": "^5.3|^7.0|^8.0"
- },
- "replace": {
- "cordoval/hamcrest-php": "*",
- "davedevelopment/hamcrest-php": "*",
- "kodova/hamcrest-php": "*"
- },
- "require-dev": {
- "phpunit/php-file-iterator": "^1.4 || ^2.0",
- "phpunit/phpunit": "^4.8.36 || ^5.7 || ^6.5 || ^7.0"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "2.1-dev"
- }
- },
- "autoload": {
- "classmap": [
- "hamcrest"
- ]
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "BSD-3-Clause"
- ],
- "description": "This is the PHP port of Hamcrest Matchers",
- "keywords": [
- "test"
- ],
- "support": {
- "issues": "https://github.com/hamcrest/hamcrest-php/issues",
- "source": "https://github.com/hamcrest/hamcrest-php/tree/v2.0.1"
- },
- "time": "2020-07-09T08:09:16+00:00"
- },
{
"name": "instaclick/php-webdriver",
"version": "1.4.19",
@@ -8850,89 +8799,6 @@
},
"time": "2024-03-31T07:05:07+00:00"
},
- {
- "name": "mockery/mockery",
- "version": "1.6.12",
- "source": {
- "type": "git",
- "url": "https://github.com/mockery/mockery.git",
- "reference": "1f4efdd7d3beafe9807b08156dfcb176d18f1699"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/mockery/mockery/zipball/1f4efdd7d3beafe9807b08156dfcb176d18f1699",
- "reference": "1f4efdd7d3beafe9807b08156dfcb176d18f1699",
- "shasum": ""
- },
- "require": {
- "hamcrest/hamcrest-php": "^2.0.1",
- "lib-pcre": ">=7.0",
- "php": ">=7.3"
- },
- "conflict": {
- "phpunit/phpunit": "<8.0"
- },
- "require-dev": {
- "phpunit/phpunit": "^8.5 || ^9.6.17",
- "symplify/easy-coding-standard": "^12.1.14"
- },
- "type": "library",
- "autoload": {
- "files": [
- "library/helpers.php",
- "library/Mockery.php"
- ],
- "psr-4": {
- "Mockery\\": "library/Mockery"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "BSD-3-Clause"
- ],
- "authors": [
- {
- "name": "Pádraic Brady",
- "email": "padraic.brady@gmail.com",
- "homepage": "https://github.com/padraic",
- "role": "Author"
- },
- {
- "name": "Dave Marshall",
- "email": "dave.marshall@atstsolutions.co.uk",
- "homepage": "https://davedevelopment.co.uk",
- "role": "Developer"
- },
- {
- "name": "Nathanael Esayeas",
- "email": "nathanael.esayeas@protonmail.com",
- "homepage": "https://github.com/ghostwriter",
- "role": "Lead Developer"
- }
- ],
- "description": "Mockery is a simple yet flexible PHP mock object framework",
- "homepage": "https://github.com/mockery/mockery",
- "keywords": [
- "BDD",
- "TDD",
- "library",
- "mock",
- "mock objects",
- "mockery",
- "stub",
- "test",
- "test double",
- "testing"
- ],
- "support": {
- "docs": "https://docs.mockery.io/",
- "issues": "https://github.com/mockery/mockery/issues",
- "rss": "https://github.com/mockery/mockery/releases.atom",
- "security": "https://github.com/mockery/mockery/security/advisories",
- "source": "https://github.com/mockery/mockery"
- },
- "time": "2024-05-16T03:13:13+00:00"
- },
{
"name": "myclabs/deep-copy",
"version": "1.12.0",
diff --git a/dev/Command/AuthenticationCommand.php b/dev/Command/AuthenticationCommand.php
index a981d8e7..64dbaf5f 100644
--- a/dev/Command/AuthenticationCommand.php
+++ b/dev/Command/AuthenticationCommand.php
@@ -174,7 +174,6 @@ protected function decorateResult(string $text): string
protected function readAuthenticationLinkFromFile(string $file, OutputInterface $output): string
{
$qrcode = new QrReader(file_get_contents($file), QrReader::SOURCE_TYPE_BLOB);
- /** @phpstan-var mixed $link */
$link = $qrcode->text();
if (!is_string($link)) {
diff --git a/tests/Unit/EventSubscriber/RequiresActiveSessionAttributeListenerTest.php b/tests/Unit/EventSubscriber/RequiresActiveSessionAttributeListenerTest.php
index e73c23db..2a47dbf0 100644
--- a/tests/Unit/EventSubscriber/RequiresActiveSessionAttributeListenerTest.php
+++ b/tests/Unit/EventSubscriber/RequiresActiveSessionAttributeListenerTest.php
@@ -17,7 +17,6 @@
namespace Unit\EventSubscriber;
-use Mockery;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
use Surfnet\Tiqr\Attribute\RequiresActiveSession;
@@ -42,8 +41,6 @@ final class RequiresActiveSessionAttributeListenerTest extends KernelTestCase
public function testControllersWithoutTheRequiresActiveSessionAttributeAreIgnored(): void
{
- $this->expectNotToPerformAssertions();
-
self::bootKernel();
$request = new Request(server: ['REQUEST_URI' => '/route']);
@@ -63,8 +60,8 @@ public function testControllersWithoutTheRequiresActiveSessionAttributeAreIgnore
$dispatcher = new EventDispatcher();
- $mockLogger = Mockery::mock(LoggerInterface::class);
- $mockLogger->shouldNotReceive('log');
+ $mockLogger = $this->createMock(LoggerInterface::class);
+ $mockLogger->expects($this->never())->method('log');
$listener = new RequiresActiveSessionAttributeListener(
$mockLogger,
@@ -101,15 +98,14 @@ public function testItDeniesAccessWhenThereIsNoActiveSession(): void
$dispatcher = new EventDispatcher();
- $mockLogger = Mockery::mock(LoggerInterface::class);
- $mockLogger->shouldReceive('log')
- ->once()
+ $mockLogger = $this->createMock(LoggerInterface::class);
+ $mockLogger->expects($this->once())
+ ->method('log')
->with(
LogLevel::ERROR,
'Route requires active session. Active session wasn\'t found.',
['correlationId' => '', 'route' => '/route']
);
-
$listener = new RequiresActiveSessionAttributeListener(
$mockLogger,
new SessionCorrelationIdService($requestStack, ['name' => 'PHPSESSID'], 'Mr6LpJYtuWRDdVR2_7VgTChFhzQ'),
@@ -146,9 +142,9 @@ public function testItDeniesAccessWhenThereIsNoSessionCookie(): void
$dispatcher = new EventDispatcher();
- $mockLogger = Mockery::mock(LoggerInterface::class);
- $mockLogger->shouldReceive('log')
- ->once()
+ $mockLogger = $this->createMock(LoggerInterface::class);
+ $mockLogger->expects($this->once())
+ ->method('log')
->with(
LogLevel::ERROR,
'Route requires active session. Active session wasn\'t found. No session cookie was set.',
@@ -191,9 +187,9 @@ public function testItDeniesAccessWhenTheActiveSessionDoesNotMatchTheSessionCook
$dispatcher = new EventDispatcher();
- $mockLogger = Mockery::mock(LoggerInterface::class);
- $mockLogger->shouldReceive('log')
- ->once()
+ $mockLogger = $this->createMock(LoggerInterface::class);
+ $mockLogger->expects($this->once())
+ ->method('log')
->with(
LogLevel::ERROR,
'Route requires active session. Session does not match session cookie.',
@@ -212,8 +208,6 @@ public function testItDeniesAccessWhenTheActiveSessionDoesNotMatchTheSessionCook
public function testItDoesNotThrowWhenTheActiveSessionMatchesTheSessionCookie(): void
{
- $this->expectNotToPerformAssertions();
-
self::bootKernel();
$session = new Session(new MockArraySessionStorage());
@@ -235,8 +229,8 @@ public function testItDoesNotThrowWhenTheActiveSessionMatchesTheSessionCookie():
$dispatcher = new EventDispatcher();
- $mockLogger = Mockery::mock(LoggerInterface::class);
- $mockLogger->shouldNotReceive('log');
+ $mockLogger = $this->createMock(LoggerInterface::class);
+ $mockLogger->expects($this->never())->method('log');
$listener = new RequiresActiveSessionAttributeListener(
$mockLogger,
diff --git a/tests/Unit/EventSubscriber/SessionStateListenerTest.php b/tests/Unit/EventSubscriber/SessionStateListenerTest.php
index d5367259..4ca1f7a9 100644
--- a/tests/Unit/EventSubscriber/SessionStateListenerTest.php
+++ b/tests/Unit/EventSubscriber/SessionStateListenerTest.php
@@ -17,7 +17,6 @@
namespace Unit\EventSubscriber;
-use Mockery;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
use Surfnet\Tiqr\EventSubscriber\SessionStateListener;
@@ -38,8 +37,6 @@ final class SessionStateListenerTest extends KernelTestCase
public function testItLogsWhenUserHasNoSessionCookie(): void
{
- $this->expectNotToPerformAssertions();
-
self::bootKernel();
$request = new Request(server: ['REQUEST_URI' => '/route']);
@@ -51,11 +48,14 @@ public function testItLogsWhenUserHasNoSessionCookie(): void
$dispatcher = new EventDispatcher();
- $mockLogger = Mockery::mock(LoggerInterface::class);
- $mockLogger->shouldReceive('log')
- ->once()
- ->with(LogLevel::INFO, 'User made a request without a session cookie.', ['correlationId' => '', 'route' => '/route']);
-
+ $mockLogger = $this->createMock(LoggerInterface::class);
+ $mockLogger->expects($this->once())
+ ->method('log')
+ ->with(
+ LogLevel::INFO,
+ 'User made a request without a session cookie.',
+ ['correlationId' => '', 'route' => '/route']
+ );
$listener = new SessionStateListener(
$mockLogger,
new SessionCorrelationIdService($requestStack, ['name' => 'PHPSESSID'], 'Mr6LpJYtuWRDdVR2_7VgTChFhzQ'),
@@ -68,8 +68,6 @@ public function testItLogsWhenUserHasNoSessionCookie(): void
public function testItLogsWhenUserHasNoSession(): void
{
- $this->expectNotToPerformAssertions();
-
self::bootKernel();
$request = new Request(server: ['REQUEST_URI' => '/route'], cookies: ['PHPSESSID' => self::SESSION_ID]);
@@ -81,13 +79,31 @@ public function testItLogsWhenUserHasNoSession(): void
$dispatcher = new EventDispatcher();
- $mockLogger = Mockery::mock(LoggerInterface::class);
- $mockLogger->shouldReceive('log')
- ->once()
- ->with(LogLevel::INFO, 'User made a request with a session cookie.', ['correlationId' => 'f6e7cfb6f0861f577c48f171e27542236b1184f7a599dde82aca1640d86da961', 'route' => '/route']);
- $mockLogger->shouldReceive('log')
- ->once()
- ->with(LogLevel::INFO, 'Session not found.', ['correlationId' => 'f6e7cfb6f0861f577c48f171e27542236b1184f7a599dde82aca1640d86da961', 'route' => '/route']);
+ $mockLogger = $this->createMock(LoggerInterface::class);
+
+ $mockLogger->expects($this->exactly(2))
+ ->method('log')
+ ->willReturnCallback(function ($level, $message, $context) {
+ static $calledMessages = [];
+
+ if (isset($calledMessages[$message])) {
+ $this->fail('Log message "' . $message . '" was called more than once.');
+ }
+ $calledMessages[$message] = true;
+
+ switch($message) {
+ case 'Session not found.':
+ case 'User made a request with a session cookie.':
+ $this->assertSame(LogLevel::INFO, $level);
+ $this->assertSame('f6e7cfb6f0861f577c48f171e27542236b1184f7a599dde82aca1640d86da961', $context['correlationId']);
+ $this->assertSame('/route', $context['route']);
+ break;
+ default:
+ $this->fail('Unexpected log message');
+ }
+
+ })
+ ;
$listener = new SessionStateListener(
$mockLogger,
@@ -101,8 +117,6 @@ public function testItLogsWhenUserHasNoSession(): void
public function testItLogsAnErrorWhenTheSessionIdDoesNotMatchTheSessionCookie(): void
{
- $this->expectNotToPerformAssertions();
-
self::bootKernel();
$session = new Session(new MockArraySessionStorage());
@@ -118,16 +132,29 @@ public function testItLogsAnErrorWhenTheSessionIdDoesNotMatchTheSessionCookie():
$dispatcher = new EventDispatcher();
- $mockLogger = Mockery::mock(LoggerInterface::class);
- $mockLogger->shouldReceive('log')
- ->once()
- ->with(LogLevel::INFO, 'User made a request with a session cookie.', ['correlationId' => 'f6e7cfb6f0861f577c48f171e27542236b1184f7a599dde82aca1640d86da961', 'route' => '/route']);
- $mockLogger->shouldReceive('log')
- ->once()
- ->with(LogLevel::INFO, 'User has a session.', ['correlationId' => 'f6e7cfb6f0861f577c48f171e27542236b1184f7a599dde82aca1640d86da961', 'route' => '/route']);
- $mockLogger->shouldReceive('log')
- ->once()
- ->with(LogLevel::ERROR, 'The session cookie does not match the session id.', ['correlationId' => 'f6e7cfb6f0861f577c48f171e27542236b1184f7a599dde82aca1640d86da961', 'route' => '/route']);
+ $mockLogger = $this->createMock(LoggerInterface::class);
+ $mockLogger->expects($this->exactly(3))
+ ->method('log')
+ ->willReturnCallback(function ($level, $message, $context) {
+ static $calledMessages = [];
+
+ if (isset($calledMessages[$message])) {
+ $this->fail('Log message "' . $message . '" was called more than once.');
+ }
+ $calledMessages[$message] = true;
+
+ switch($message) {
+ case 'User made a request with a session cookie.':
+ case 'User has a session.':
+ case 'The session cookie does not match the session id.':
+ $this->assertSame($level === LogLevel::ERROR ? LogLevel::ERROR : LogLevel::INFO, $level);
+ $this->assertSame('f6e7cfb6f0861f577c48f171e27542236b1184f7a599dde82aca1640d86da961', $context['correlationId']);
+ $this->assertSame('/route', $context['route']);
+ break;
+ default:
+ $this->fail('Unexpected log message');
+ }
+ });
$listener = new SessionStateListener(
$mockLogger,
@@ -141,8 +168,6 @@ public function testItLogsAnErrorWhenTheSessionIdDoesNotMatchTheSessionCookie():
public function testTheUserSessionMatchesTheSessionCookie(): void
{
- $this->expectNotToPerformAssertions();
-
self::bootKernel();
$session = new Session(new MockArraySessionStorage());
@@ -159,16 +184,29 @@ public function testTheUserSessionMatchesTheSessionCookie(): void
$dispatcher = new EventDispatcher();
- $mockLogger = Mockery::mock(LoggerInterface::class);
- $mockLogger->shouldReceive('log')
- ->once()
- ->with(LogLevel::INFO, 'User made a request with a session cookie.', ['correlationId' => 'f6e7cfb6f0861f577c48f171e27542236b1184f7a599dde82aca1640d86da961', 'route' => '/route']);
- $mockLogger->shouldReceive('log')
- ->once()
- ->with(LogLevel::INFO, 'User has a session.', ['correlationId' => 'f6e7cfb6f0861f577c48f171e27542236b1184f7a599dde82aca1640d86da961', 'route' => '/route']);
- $mockLogger->shouldReceive('log')
- ->once()
- ->with(LogLevel::INFO, 'User session matches the session cookie.', ['correlationId' => 'f6e7cfb6f0861f577c48f171e27542236b1184f7a599dde82aca1640d86da961', 'route' => '/route']);
+ $mockLogger = $this->createMock(LoggerInterface::class);
+ $mockLogger->expects($this->exactly(3))
+ ->method('log')
+ ->willReturnCallback(function ($level, $message, $context) {
+ static $calledMessages = [];
+
+ if (isset($calledMessages[$message])) {
+ $this->fail('Log message "' . $message . '" was called more than once.');
+ }
+ $calledMessages[$message] = true;
+
+ switch($message) {
+ case 'User made a request with a session cookie.':
+ case 'User has a session.':
+ case 'User session matches the session cookie.':
+ $this->assertSame(LogLevel::INFO, $level);
+ $this->assertSame('f6e7cfb6f0861f577c48f171e27542236b1184f7a599dde82aca1640d86da961', $context['correlationId']);
+ $this->assertSame('/route', $context['route']);
+ break;
+ default:
+ $this->fail('Unexpected log message');
+ }
+ });
$listener = new SessionStateListener(
$mockLogger,
diff --git a/tests/Unit/Session/LoggingSessionFactoryTest.php b/tests/Unit/Session/LoggingSessionFactoryTest.php
index 6399f95e..8c77f9d6 100644
--- a/tests/Unit/Session/LoggingSessionFactoryTest.php
+++ b/tests/Unit/Session/LoggingSessionFactoryTest.php
@@ -17,7 +17,6 @@
namespace Unit\Session;
-use Mockery;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
use Surfnet\Tiqr\Service\SessionCorrelationIdService;
@@ -36,11 +35,14 @@ public function testItLogsWheneverASessionIsCreated(): void
$requestStack = new RequestStack();
$requestStack->push($request);
- $mockLogger = Mockery::mock(LoggerInterface::class);
- $mockLogger->shouldReceive('log')
- ->once()
- ->with(LogLevel::INFO, 'Created new session.', ['correlationId' => 'f6e7cfb6f0861f577c48f171e27542236b1184f7a599dde82aca1640d86da961']);
-
+ $mockLogger = $this->createMock(LoggerInterface::class);
+ $mockLogger->expects($this->once())
+ ->method('log')
+ ->with(
+ LogLevel::INFO,
+ 'Created new session.',
+ ['correlationId' => 'f6e7cfb6f0861f577c48f171e27542236b1184f7a599dde82aca1640d86da961']
+ );
$sessionFactory = new LoggingSessionFactory(
$requestStack,
$this->createStub(SessionStorageFactoryInterface::class),