From 3dffbabb842fe7ecd588fb6971c81bdc706220e3 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 10 Sep 2024 16:41:46 +1200 Subject: [PATCH] DEP Use PHPUnit 11 --- composer.json | 2 +- .../CheckComposerUpdatesExtensionTest.php | 6 +++--- tests/UpdateCheckerTest.php | 18 ++++++++++++------ 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index 72496cc..1c0023b 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ "bringyourownideas/silverstripe-maintenance": "^4" }, "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/Extensions/CheckComposerUpdatesExtensionTest.php b/tests/Extensions/CheckComposerUpdatesExtensionTest.php index be33726..f4fc530 100644 --- a/tests/Extensions/CheckComposerUpdatesExtensionTest.php +++ b/tests/Extensions/CheckComposerUpdatesExtensionTest.php @@ -43,7 +43,7 @@ protected function setUp(): void $this->task = UpdatePackageInfoTask::create(); // Create a partial mock of the update checker - $updateCheckerMock = $this->getMockBuilder(UpdateChecker::class)->setMethods(['checkForUpdates'])->getMock(); + $updateCheckerMock = $this->getMockBuilder(UpdateChecker::class)->onlyMethods(['checkForUpdates'])->getMock(); $this->task->setUpdateChecker($updateCheckerMock); $this->allowedTypes = ['silverstripe-module', 'silverstripe-vendormodule', 'silverstripe-theme']; @@ -55,7 +55,7 @@ public function testRunPassesPackagesToUpdateChecker() $this->task->getUpdateChecker()->expects($this->atLeastOnce()) ->method('checkForUpdates') ->with($this->isInstanceOf(PackageInterface::class), $this->isType('string')) - ->will($this->returnValue([])); + ->willReturn([]); $this->runTask(); } @@ -67,7 +67,7 @@ public function testOnlyAllowedPackageTypesAreProcessed() ->with($this->callback(function ($argument) { return in_array($argument->getType(), $this->allowedTypes); })) - ->will($this->returnValue([])); + ->willReturn([]); $this->runTask(); } diff --git a/tests/UpdateCheckerTest.php b/tests/UpdateCheckerTest.php index 53d662c..1181680 100644 --- a/tests/UpdateCheckerTest.php +++ b/tests/UpdateCheckerTest.php @@ -23,16 +23,22 @@ protected function setUp(): void // Mock composer and composer loader $composer = $this->getMockBuilder(Composer::class)->getMock(); - $composerLoader = $this->getMockBuilder(ComposerLoader::class) - ->disableOriginalConstructor() - ->setMethods(['getComposer']) - ->getMock(); - $composerLoader->expects($this->once())->method('getComposer')->will($this->returnValue($composer)); + $composerLoader = new class ($composer) extends ComposerLoader { + private $composer; + public function __construct($composer) + { + $this->composer = $composer; + } + public function getComposer(): Composer + { + return $this->composer; + } + }; Injector::inst()->registerService($composerLoader, ComposerLoader::class); // Partially mock UpdateChecker $this->updateChecker = $this->getMockBuilder(UpdateChecker::class) - ->setMethods(['findLatestPackage']) + ->onlyMethods(['findLatestPackage']) ->getMock(); }