From f66677d80081af61189f697ede9cdaaf4158257e Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 10 Sep 2024 11:28:59 +1200 Subject: [PATCH] DEP Use PHPUnit 11 --- composer.json | 2 +- .../HistoryViewerControllerTest.php | 21 ++++++++----------- tests/Extensions/FileArchiveExtensionTest.php | 7 +++---- tests/Forms/DiffFieldTest.php | 7 +++---- .../GridFieldFileRestoreActionTest.php | 2 +- 5 files changed, 17 insertions(+), 22 deletions(-) diff --git a/composer.json b/composer.json index 92860282..0a3a55a0 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "silverstripe/vendor-plugin": "^2" }, "require-dev": { - "phpunit/phpunit": "^9.6", + "phpunit/phpunit": "^11.3", "squizlabs/php_codesniffer": "^3.7", "silverstripe/cms": "^6", "silverstripe/frameworktest": "^2", diff --git a/tests/Controllers/HistoryViewerControllerTest.php b/tests/Controllers/HistoryViewerControllerTest.php index 9148cbfe..8d315971 100644 --- a/tests/Controllers/HistoryViewerControllerTest.php +++ b/tests/Controllers/HistoryViewerControllerTest.php @@ -16,6 +16,7 @@ use SilverStripe\Security\SecurityToken; use SilverStripe\Versioned\Versioned; use SilverStripe\VersionedAdmin\Forms\HistoryViewerField; +use PHPUnit\Framework\Attributes\DataProvider; class HistoryViewerControllerTest extends FunctionalTest { @@ -63,7 +64,7 @@ public function testGetClientConfig() public function testSchema() { $controllerMock = $this->getMockBuilder(HistoryViewerController::class) - ->setMethods(['getVersionForm', 'getCompareForm', 'getSchemaResponse']) + ->onlyMethods(['getVersionForm', 'getCompareForm', 'getSchemaResponse']) ->getMock(); $controllerMock->expects($this->once())->method('getVersionForm')->with([ @@ -84,7 +85,7 @@ public function testSchema() $request = $this->getMockBuilder(HTTPRequest::class) ->setConstructorArgs(['GET', '/']) - ->setMethods(['param']) + ->onlyMethods(['param']) ->getMock(); $request->expects($this->once())->method('param')->with('FormName')->willReturn('versionForm'); $request->offsetSet('RecordClass', 'Page'); @@ -98,7 +99,7 @@ public function testSchema() $request = $this->getMockBuilder(HTTPRequest::class) ->setConstructorArgs(['GET', '/']) - ->setMethods(['param']) + ->onlyMethods(['param']) ->getMock(); $request->expects($this->once())->method('param')->with('FormName')->willReturn('compareForm'); $request->offsetSet('RecordClass', 'Page'); @@ -202,7 +203,7 @@ public function testVersionFormThrowsExceptionWhenArgsAreFalsy() public function testVersionFormReturnsVersionForm() { $controllerMock = $this->getMockBuilder(HistoryViewerController::class) - ->setMethods(['getVersionForm']) + ->onlyMethods(['getVersionForm']) ->getMock(); $mockData = [ @@ -220,7 +221,7 @@ public function testVersionFormReturnsVersionForm() $this->assertSame('mocked', $result); } - public function provideApiRead(): array + public static function provideApiRead(): array { return [ 'Valid' => [ @@ -271,9 +272,7 @@ public function provideApiRead(): array ]; } - /** - * @dataProvider provideApiRead - */ + #[DataProvider('provideApiRead')] public function testApiRead( string $idType, string $fail, @@ -404,7 +403,7 @@ public function testApiRead( } } - public function provideApiRevert(): array + public static function provideApiRevert(): array { return [ 'Valid' => [ @@ -470,9 +469,7 @@ public function provideApiRevert(): array ]; } - /** - * @dataProvider provideApiRevert - */ + #[DataProvider('provideApiRevert')] public function testApiRevert( string $idType, string $fail, diff --git a/tests/Extensions/FileArchiveExtensionTest.php b/tests/Extensions/FileArchiveExtensionTest.php index 02004895..bca8dbfa 100644 --- a/tests/Extensions/FileArchiveExtensionTest.php +++ b/tests/Extensions/FileArchiveExtensionTest.php @@ -6,12 +6,11 @@ use SilverStripe\Assets\AssetControlExtension; use SilverStripe\Core\Config\Config; use SilverStripe\Assets\File; +use PHPUnit\Framework\Attributes\DataProvider; class FileArchiveExtensionTest extends SapphireTest { - /** - * @dataProvider provideIsArchiveFieldEnabled - */ + #[DataProvider('provideIsArchiveFieldEnabled')] public function testIsArchiveFieldEnabled( bool $assetControlExtension, bool $file, @@ -23,7 +22,7 @@ public function testIsArchiveFieldEnabled( $this->assertSame($expected, $actual); } - public function provideIsArchiveFieldEnabled(): array + public static function provideIsArchiveFieldEnabled(): array { return [ [ diff --git a/tests/Forms/DiffFieldTest.php b/tests/Forms/DiffFieldTest.php index ca1582f1..a2ef2fc8 100644 --- a/tests/Forms/DiffFieldTest.php +++ b/tests/Forms/DiffFieldTest.php @@ -10,6 +10,7 @@ use SilverStripe\ORM\ManyManyList; use SilverStripe\Security\Group; use SilverStripe\VersionedAdmin\Forms\DiffField; +use PHPUnit\Framework\Attributes\DataProvider; class DiffFieldTest extends SapphireTest { @@ -38,9 +39,7 @@ public function testObjectValuesAreNotDiffed() $this->assertEquals('(No diff available)', $diffField->Value()); } - /** - * @dataProvider provideEscaping - */ + #[DataProvider('provideEscaping')] public function testEscaping( string $className, string $oldValue, @@ -62,7 +61,7 @@ public function testEscaping( $this->assertSame($expected, $diffField->Value(), $message); } - public function provideEscaping() + public static function provideEscaping() { return [ [ diff --git a/tests/Forms/GridField/GridFieldFileRestoreActionTest.php b/tests/Forms/GridField/GridFieldFileRestoreActionTest.php index bc2f3586..a9ec3b40 100644 --- a/tests/Forms/GridField/GridFieldFileRestoreActionTest.php +++ b/tests/Forms/GridField/GridFieldFileRestoreActionTest.php @@ -23,7 +23,7 @@ public function testGetRestoreAction() $this->assertNull($action->getRestoreAction($gridField, new File(), 'Test')); $file = $this->getMockBuilder(File::class) - ->setMethods(['exists']) + ->onlyMethods(['exists']) ->getMock(); $file->method('exists') ->willReturn(true);