From f677f86ccc76083737eedc8861ebac25a1f41d44 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 11 Sep 2024 11:58:44 +1200 Subject: [PATCH] DEP Use PHPUnit 11 --- composer.json | 2 +- tests/php/LeftAndMainTest.php | 24 ++++++++++-------------- tests/php/ModelAdminTest.php | 10 +++++----- 3 files changed, 16 insertions(+), 20 deletions(-) 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..ec76a65ec 100644 --- a/tests/php/LeftAndMainTest.php +++ b/tests/php/LeftAndMainTest.php @@ -19,6 +19,8 @@ use stdClass; use ReflectionObject; use InvalidArgumentException; +use PHPUnit\Framework\Attributes\DataProvider; +use SilverStripe\Core\Manifest\VersionProvider; class LeftAndMainTest extends FunctionalTest { @@ -218,21 +220,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 +241,7 @@ public function testCMSVersionNumber($frameworkVersion, $expected) /** * @return array */ - public function provideTestCMSVersionNumber() + public static function provideTestCMSVersionNumber() { return [ ['4.9.1', '4.9'], @@ -290,7 +290,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 +338,7 @@ public function provideJsonSuccess(): array ]; } - /** - * @dataProvider provideJsonSuccess - */ + #[DataProvider('provideJsonSuccess')] public function testJsonSuccess( int $statusCode, ?array $data, @@ -360,7 +358,7 @@ public function testJsonSuccess( $this->assertSame($expectedBody, $response->getBody()); } - public function provideJsonError(): array + public static function provideJsonError(): array { return [ [ @@ -406,9 +404,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);