From 5f81c401bdda6b42a9ad313fa0b75ca0f2b1ea6c Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 10 Sep 2024 18:03:57 +1200 Subject: [PATCH] DEP Use PHPUnit 11 --- composer.json | 2 +- tests/EnvironmentCheckerTest.php | 30 +++++++++++++++++------------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index 6503324..4778d07 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "guzzlehttp/guzzle": "^7" }, "require-dev": { - "phpunit/phpunit": "^9.6", + "phpunit/phpunit": "^11.3", "squizlabs/php_codesniffer": "^3", "silverstripe/standards": "^1", "phpstan/extension-installer": "^1.3" diff --git a/tests/EnvironmentCheckerTest.php b/tests/EnvironmentCheckerTest.php index f8e2c02..6da507c 100644 --- a/tests/EnvironmentCheckerTest.php +++ b/tests/EnvironmentCheckerTest.php @@ -35,7 +35,7 @@ class EnvironmentCheckerTest extends SapphireTest $logger = $this->getMockBuilder(Logger::class) ->disableOriginalConstructor() - ->setMethods(['log']) + ->onlyMethods(['log']) ->getMock(); $logger->expects($this->never())->method('log'); @@ -55,15 +55,17 @@ class EnvironmentCheckerTest extends SapphireTest $logger = $this->getMockBuilder(Logger::class) ->disableOriginalConstructor() - ->setMethods(['log']) + ->onlyMethods(['log']) ->getMock(); - $logger->expects($this->once()) + $matcher = $this->once(); + $logger->expects($matcher) ->method('log') - ->withConsecutive( - [$this->equalTo(LogLevel::WARNING)], - [$this->anything()] - ); + ->willReturnCallback(function (mixed $level) use ($matcher) { + match ($matcher->numberOfInvocations()) { + 1 => $this->assertSame(LogLevel::WARNING, $level), + }; + }); Injector::inst()->registerService($logger, LoggerInterface::class); @@ -80,15 +82,17 @@ class EnvironmentCheckerTest extends SapphireTest $logger = $this->getMockBuilder(Logger::class) ->disableOriginalConstructor() - ->setMethods(['log']) + ->onlyMethods(['log']) ->getMock(); - $logger->expects($this->once()) + $matcher = $this->once(); + $logger->expects($matcher) ->method('log') - ->withConsecutive( - [$this->equalTo(LogLevel::ALERT), $this->anything()], - [$this->equalTo(LogLevel::WARNING), $this->anything()] - ); + ->willReturnCallback(function (mixed $level) use ($matcher) { + match ($matcher->numberOfInvocations()) { + 1 => $this->assertSame(LogLevel::ALERT, $level), + }; + }); Injector::inst()->registerService($logger, LoggerInterface::class);