diff --git a/composer.json b/composer.json index a8c25bdb8..a28cb2ddf 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "silverstripe/vendor-plugin": "^2" }, "require-dev": { - "phpunit/phpunit": "^9.6", + "phpunit/phpunit": "^11.3", "silverstripe/frameworktest": "^2", "squizlabs/php_codesniffer": "^3.7", "silverstripe/standards": "^1", diff --git a/tests/php/LeftAndMainTest.php b/tests/php/LeftAndMainTest.php index 9bb4c6697..d9cc7bb9e 100644 --- a/tests/php/LeftAndMainTest.php +++ b/tests/php/LeftAndMainTest.php @@ -19,6 +19,7 @@ use stdClass; use ReflectionObject; use InvalidArgumentException; +use PHPUnit\Framework\Attributes\DataProvider; class LeftAndMainTest extends FunctionalTest { @@ -218,21 +219,19 @@ public function testDisableHelpLinks() $this->assertCount(0, $helpLinks); } - /** - * @dataProvider provideTestCMSVersionNumber - */ + #[DataProvider('provideTestCMSVersionNumber')] public function testCMSVersionNumber($frameworkVersion, $expected) { $versionProvider = $this ->getMockBuilder(VersionProvider::class) - ->setMethods(['getModules', 'getModuleVersionFromComposer']) + ->onlyMethods(['getModules', 'getModuleVersionFromComposer']) ->getMock(); $data = ['silverstripe/framework' => $frameworkVersion]; $versionProvider->method('getModules')->willReturn($data); $versionProvider->method('getModuleVersionFromComposer')->willReturn($data); $leftAndMain = $this ->getMockBuilder(LeftAndMain::class) - ->setMethods(['getVersionProvider']) + ->onlyMethods(['getVersionProvider']) ->getMock(); $leftAndMain->method('getVersionProvider')->willReturn($versionProvider); $this->assertSame($expected, $leftAndMain->CMSVersionNumber()); @@ -241,7 +240,7 @@ public function testCMSVersionNumber($frameworkVersion, $expected) /** * @return array */ - public function provideTestCMSVersionNumber() + public static function provideTestCMSVersionNumber() { return [ ['4.9.1', '4.9'], @@ -290,7 +289,7 @@ public function testValidationResult() $this->assertSame($result->messages[0]->message, MyTree::INVALID_CONTENT_MESSAGE); } - public function provideJsonSuccess(): array + public static function provideJsonSuccess(): array { return [ [ @@ -338,9 +337,7 @@ public function provideJsonSuccess(): array ]; } - /** - * @dataProvider provideJsonSuccess - */ + #[DataProvider('provideJsonSuccess')] public function testJsonSuccess( int $statusCode, ?array $data, @@ -360,7 +357,7 @@ public function testJsonSuccess( $this->assertSame($expectedBody, $response->getBody()); } - public function provideJsonError(): array + public static function provideJsonError(): array { return [ [ @@ -406,9 +403,7 @@ public function provideJsonError(): array ]; } - /** - * @dataProvider provideJsonError - */ + #[DataProvider('provideJsonError')] public function testJsonError( int $statusCode, ?string $errorMessage, diff --git a/tests/php/ModelAdminTest.php b/tests/php/ModelAdminTest.php index d4fea6ade..817d5bc9f 100644 --- a/tests/php/ModelAdminTest.php +++ b/tests/php/ModelAdminTest.php @@ -220,14 +220,14 @@ public function testGetManagedModels() public function testGetManagedModelTabs() { $mock = $this->getMockBuilder(ModelAdminTest\MultiModelAdmin::class) - ->setMethods(['getManagedModels']) + ->onlyMethods(['getManagedModels']) ->getMock(); // `getManagedModelTabs` relies on `getManagedModels` whose output format has changed within the 4.x line. // We need to mock `getManagedModels` so it returns both the legacy and updated format. $mock->expects($this->atLeastOnce()) ->method('getManagedModels') - ->will($this->returnValue([ + ->willReturn([ 'Player' => [ 'dataClass' => Player::class, 'title' => 'Ice Hockey Players' @@ -239,7 +239,7 @@ public function testGetManagedModelTabs() 'dataClass' => Player::class, 'title' => 'Cricket Players', ], - ])); + ]); $tabs = $mock->getManagedModelTabs()->toNestedArray(); @@ -386,11 +386,11 @@ public function testGetModelTabForModelClassNoSpec() // We need to mock `getManagedModels` to test the legacy format. $mock->expects($this->atLeastOnce()) ->method('getManagedModels') - ->will($this->returnValue([ + ->willReturn([ Player::class => [ 'title' => 'Rugby Players' ], - ])); + ]); $reflectionMethod = new ReflectionMethod($mock, 'getModelTabForModelClass'); $reflectionMethod->setAccessible(true);