diff --git a/composer.json b/composer.json index 7ea9ded..f461963 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "guzzlehttp/guzzle": "^7.5" }, "require-dev": { - "phpunit/phpunit": "^9.6", + "phpunit/phpunit": "^11.3", "squizlabs/php_codesniffer": "^3", "symfony/thanks": "^1.2", "silverstripe/standards": "^1", diff --git a/tests/Forms/GridFieldRefreshButtonTest.php b/tests/Forms/GridFieldRefreshButtonTest.php index 34eb563..8441f22 100644 --- a/tests/Forms/GridFieldRefreshButtonTest.php +++ b/tests/Forms/GridFieldRefreshButtonTest.php @@ -118,13 +118,13 @@ protected function getGridFieldMock() $gridFieldMock = $this ->getMockBuilder(GridField::class) ->setConstructorArgs(['TestGridField']) - ->setMethods(['Link']) + ->onlyMethods(['Link']) ->getMock(); $gridFieldMock ->expects($this->any()) ->method('Link') - ->will($this->returnValue('http://example.com')); + ->willReturn('http://example.com'); return $gridFieldMock; } diff --git a/tests/Model/PackageTest.php b/tests/Model/PackageTest.php index 4392c07..70f8a3b 100644 --- a/tests/Model/PackageTest.php +++ b/tests/Model/PackageTest.php @@ -6,10 +6,11 @@ use SilverStripe\Dev\SapphireTest; use SilverStripe\ORM\ArrayList; use SilverStripe\View\ArrayData; +use PHPUnit\Framework\Attributes\DataProvider; class PackageTest extends SapphireTest { - public function providePackageNamesAndTitles() + public static function providePackageNamesAndTitles() { return [ ['pretendvendor/silverstripe-prefixedpackage', 'prefixedpackage'], @@ -26,10 +27,10 @@ public function providePackageNamesAndTitles() } /** - * @dataProvider providePackageNamesAndTitles * * Ensure the vendor and 'silverstripe-' is stripped from module names. */ + #[DataProvider('providePackageNamesAndTitles')] public function testTitleFormatsNameCorrectly($name, $title) { $testPackage = new Package([ diff --git a/tests/Tasks/UpdatePackageInfoTest.php b/tests/Tasks/UpdatePackageInfoTest.php index cdb11a1..2c7360f 100644 --- a/tests/Tasks/UpdatePackageInfoTest.php +++ b/tests/Tasks/UpdatePackageInfoTest.php @@ -60,8 +60,8 @@ public function getModuleVersion(string $module): string }; Injector::inst()->registerService(new $mockVersionProvider(), VersionProvider::class); $composerLoader = $this->getMockBuilder(ComposerLoader::class) - ->setMethods(['getLock'])->getMock(); - $composerLoader->expects($this->any())->method('getLock')->will($this->returnValue(json_decode(<<onlyMethods(['getLock'])->getMock(); + $composerLoader->expects($this->any())->method('getLock')->willReturn(json_decode(<<setComposerLoader($composerLoader); diff --git a/tests/Util/ApiLoaderTest.php b/tests/Util/ApiLoaderTest.php index 2bf1043..8281e00 100644 --- a/tests/Util/ApiLoaderTest.php +++ b/tests/Util/ApiLoaderTest.php @@ -11,6 +11,7 @@ use SilverStripe\Dev\SapphireTest; use Psr\SimpleCache\CacheInterface; use ReflectionMethod; +use PHPUnit\Framework\Attributes\DataProvider; class ApiLoaderTest extends SapphireTest { @@ -40,8 +41,6 @@ private function getFakeJson(): array /** * Note: contains some logic from SupportedAddonsLoader for context - * - * @group integration */ public function testAddonsAreParsedAndReturnedCorrectly() { @@ -61,18 +60,16 @@ public function testAddonsAreParsedAndReturnedCorrectly() /** * Note: contains some logic from SupportedAddonsLoader for context - * - * @group integration */ public function testCacheControlSettingsAreRespected() { $cacheMock = $this->getMockCacheInterface(); - $cacheMock->expects($this->once())->method('get')->will($this->returnValue(false)); + $cacheMock->expects($this->once())->method('get')->willReturn(false); $cacheMock->expects($this->once()) ->method('set') ->with($this->anything(), '["foo\/bar","bin\/baz"]', 5000) - ->will($this->returnValue(true)); + ->willReturn(true); $loader = $this->getLoader($cacheMock); $loader->setGuzzleClient($this->getMockClient(new Response( @@ -90,10 +87,10 @@ public function testCachedAddonsAreUsedWhenAvailable() { $cacheMock = $this->getMockCacheInterface(); - $cacheMock->expects($this->once())->method('get')->will($this->returnValue(json_encode($this->getFakeJson()))); + $cacheMock->expects($this->once())->method('get')->willReturn(json_encode($this->getFakeJson())); $loader = $this->getLoader($cacheMock); - $mockClient = $this->getMockBuilder(Client::class)->setMethods(['send'])->getMock(); + $mockClient = $this->getMockBuilder(Client::class)->onlyMethods(['send'])->getMock(); $mockClient->expects($this->never())->method('send'); $loader->setGuzzleClient($mockClient); @@ -104,9 +101,7 @@ public function testCachedAddonsAreUsedWhenAvailable() $this->assertSame($this->getFakeJson(), $addons); } - /** - * @dataProvider provideParseResponseContentsEmpty - */ + #[DataProvider('provideParseResponseContentsEmpty')] public function testParseResponseContentsEmpty(string $contents) { // ApiLoader is an abstract class @@ -125,7 +120,7 @@ protected function getCacheKey() $inst->parseResponseContents($contents, $failureMessage); } - public function provideParseResponseContentsEmpty(): array + public static function provideParseResponseContentsEmpty(): array { return [ [ @@ -179,15 +174,15 @@ protected function getLoader($cacheMock = false) if (!$cacheMock) { $cacheMock = $this->getMockCacheInterface(); - $cacheMock->expects($this->any())->method('get')->will($this->returnValue(false)); - $cacheMock->expects($this->any())->method('set')->will($this->returnValue(true)); + $cacheMock->expects($this->any())->method('get')->willReturn(false); + $cacheMock->expects($this->any())->method('set')->willReturn(true); } $loader = $this->getMockBuilder(ApiLoader::class) ->getMockForAbstractClass(); $loader->setCache($cacheMock); - $loader->expects($this->any())->method('getCacheKey')->will($this->returnValue('cacheKey')); + $loader->expects($this->any())->method('getCacheKey')->willReturn('cacheKey'); return $loader; } diff --git a/tests/Util/ModuleHealthLoaderTest.php b/tests/Util/ModuleHealthLoaderTest.php index c6ed3df..06722b9 100644 --- a/tests/Util/ModuleHealthLoaderTest.php +++ b/tests/Util/ModuleHealthLoaderTest.php @@ -15,7 +15,7 @@ protected function setUp(): void parent::setUp(); $this->loader = $this->getMockBuilder(ModuleHealthLoader::class) - ->setMethods(['doRequest']) + ->onlyMethods(['doRequest']) ->getMock(); } diff --git a/tests/Util/SupportedAddonsLoaderTest.php b/tests/Util/SupportedAddonsLoaderTest.php index 413544f..36464e6 100644 --- a/tests/Util/SupportedAddonsLoaderTest.php +++ b/tests/Util/SupportedAddonsLoaderTest.php @@ -17,7 +17,7 @@ protected function setUp(): void parent::setUp(); $this->loader = $this->getMockBuilder(SupportedAddonsLoader::class) - ->setMethods(['doRequest']) + ->onlyMethods(['doRequest']) ->getMock(); }