From cbbec51a83272a02d97a1ef372602b427d7e0853 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 10 Sep 2024 16:50:20 +1200 Subject: [PATCH] DEP Use PHPUnit 11 --- composer.json | 2 +- tests/php/Controllers/CMSMainTest.php | 4 +-- .../php/Controllers/ContentControllerTest.php | 1 - .../php/Controllers/ModelAsControllerTest.php | 3 -- tests/php/Model/RedirectorPageTest.php | 13 +++----- tests/php/Model/SiteTreePermissionsTest.php | 5 +-- tests/php/Model/SiteTreeTest.php | 32 +++++++------------ tests/php/Search/ZZZSearchFormTest.php | 3 -- 8 files changed, 22 insertions(+), 41 deletions(-) diff --git a/composer.json b/composer.json index 6116ad2ecd..2b49f8d0d9 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "silverstripe/vendor-plugin": "^2" }, "require-dev": { - "phpunit/phpunit": "^9.6", + "phpunit/phpunit": "^11.3", "squizlabs/php_codesniffer": "^3.7", "silverstripe/standards": "^1", "phpstan/extension-installer": "^1.3" diff --git a/tests/php/Controllers/CMSMainTest.php b/tests/php/Controllers/CMSMainTest.php index 6c67b6fa18..205166b404 100644 --- a/tests/php/Controllers/CMSMainTest.php +++ b/tests/php/Controllers/CMSMainTest.php @@ -619,14 +619,14 @@ public function testSiteTreeHintsCache() Security::setCurrentUser($user); $pageClass = array_values(SiteTree::page_type_classes())[0]; $mockPageMissesCache = $this->getMockBuilder($pageClass) - ->setMethods(['canCreate']) + ->onlyMethods(['canCreate']) ->getMock(); $mockPageMissesCache ->expects($this->exactly(3)) ->method('canCreate'); $mockPageHitsCache = $this->getMockBuilder($pageClass) - ->setMethods(['canCreate']) + ->onlyMethods(['canCreate']) ->getMock(); $mockPageHitsCache ->expects($this->never()) diff --git a/tests/php/Controllers/ContentControllerTest.php b/tests/php/Controllers/ContentControllerTest.php index 476a23f6ed..b661fd6dd6 100644 --- a/tests/php/Controllers/ContentControllerTest.php +++ b/tests/php/Controllers/ContentControllerTest.php @@ -157,7 +157,6 @@ public function testLinkShortcodes() /** * Tests that {@link ContentController::getViewer()} chooses the correct templates. * - * @covers \SilverStripe\CMS\Controllers\ContentController::getViewer() **/ public function testGetViewer() { diff --git a/tests/php/Controllers/ModelAsControllerTest.php b/tests/php/Controllers/ModelAsControllerTest.php index 57e6206fab..60c4351eba 100644 --- a/tests/php/Controllers/ModelAsControllerTest.php +++ b/tests/php/Controllers/ModelAsControllerTest.php @@ -207,7 +207,6 @@ public function testDoesntRedirectToNestedChildrenOutsideOfOwnHierarchy() /** * * NOTE: This test requires nested_urls - * */ public function testRedirectsNestedRenamedPagesWithGetParameters() { @@ -225,7 +224,6 @@ public function testRedirectsNestedRenamedPagesWithGetParameters() /** * * NOTE: This test requires nested_urls - * */ public function testDoesntRedirectToNestedRenamedPageWhenNewExists() { @@ -255,7 +253,6 @@ public function testDoesntRedirectToNestedRenamedPageWhenNewExists() /** * * NOTE: This test requires nested_urls - * */ public function testFindOldPage() { diff --git a/tests/php/Model/RedirectorPageTest.php b/tests/php/Model/RedirectorPageTest.php index d5e4b933a8..e811845867 100644 --- a/tests/php/Model/RedirectorPageTest.php +++ b/tests/php/Model/RedirectorPageTest.php @@ -11,6 +11,7 @@ use SilverStripe\Control\Controller; use SilverStripe\Core\Config\Config; use SilverStripe\Dev\FunctionalTest; +use PHPUnit\Framework\Attributes\DataProvider; class RedirectorPageTest extends FunctionalTest { @@ -61,7 +62,7 @@ public function testGoodRedirectors() ); } - public function provideEmptyRedirectors() + public static function provideEmptyRedirectors() { return [ 'use 200' => [ @@ -73,9 +74,7 @@ public function provideEmptyRedirectors() ]; } - /** - * @dataProvider provideEmptyRedirectors - */ + #[DataProvider('provideEmptyRedirectors')] public function testEmptyRedirectors(bool $use404) { Config::modify()->set(RedirectorPageController::class, 'missing_redirect_is_404', $use404); @@ -181,7 +180,7 @@ public function testFileRedirector() $this->assertStringContainsString("FileTest.txt", $page->Link()); } - public function provideUnpublishedTarget() + public static function provideUnpublishedTarget() { return [ 'use 200 with sitetree' => [ @@ -203,9 +202,7 @@ public function provideUnpublishedTarget() ]; } - /** - * @dataProvider provideUnpublishedTarget - */ + #[DataProvider('provideUnpublishedTarget')] public function testUnpublishedTarget(bool $use404, bool $isFile) { Config::modify()->set(RedirectorPageController::class, 'missing_redirect_is_404', $use404); diff --git a/tests/php/Model/SiteTreePermissionsTest.php b/tests/php/Model/SiteTreePermissionsTest.php index 2fdf721f2d..5241137182 100644 --- a/tests/php/Model/SiteTreePermissionsTest.php +++ b/tests/php/Model/SiteTreePermissionsTest.php @@ -11,6 +11,7 @@ use SilverStripe\SiteConfig\SiteConfig; use SilverStripe\Subsites\Extensions\SiteTreeSubsites; use SilverStripe\Versioned\Versioned; +use PHPUnit\Framework\Attributes\DataProvider; class SiteTreePermissionsTest extends FunctionalTest { @@ -524,8 +525,8 @@ public function testInheritCanEditFromSiteConfig() /** * Test permissions on duplicate page - * @dataProvider groupWithPermissions */ + #[DataProvider('groupWithPermissions')] public function testDuplicatePageWithGroupPermissions(string $userName, string $method, bool $expected) { $originalPage = $this->objFromFixture(SiteTree::class, 'originalpage'); @@ -538,7 +539,7 @@ public function testDuplicatePageWithGroupPermissions(string $userName, string $ $this->assertSame($dupe->{$method}($user), $expected); } - public function groupWithPermissions(): array + public static function groupWithPermissions(): array { return [ 'Subadmin can view page duplicate.' => [ diff --git a/tests/php/Model/SiteTreeTest.php b/tests/php/Model/SiteTreeTest.php index 82485baf02..52155a3f56 100644 --- a/tests/php/Model/SiteTreeTest.php +++ b/tests/php/Model/SiteTreeTest.php @@ -42,6 +42,7 @@ use PageController; use const RESOURCES_DIR; +use PHPUnit\Framework\Attributes\DataProvider; class SiteTreeTest extends SapphireTest { @@ -71,7 +72,7 @@ class SiteTreeTest extends SapphireTest NotPageObject::class, ]; - public function reservedSegmentsProvider() + public static function reservedSegmentsProvider() { return [ // segments reserved by rules @@ -142,8 +143,8 @@ public function testURLGeneration() /** * Check if reserved URL's are properly appended with a number at top level - * @dataProvider reservedSegmentsProvider */ + #[DataProvider('reservedSegmentsProvider')] public function testDisallowedURLGeneration($title, $urlSegment) { $page = new SiteTree(['Title' => $title]); @@ -155,8 +156,8 @@ public function testDisallowedURLGeneration($title, $urlSegment) /** * Check if reserved URL's are not appended with a number on a child page * It's okay to have a URL like domain.com/my-page/admin as it won't interfere with domain.com/admin - * @dataProvider reservedSegmentsProvider */ + #[DataProvider('reservedSegmentsProvider')] public function testDisallowedChildURLGeneration($title, $urlSegment) { // Using the same dataprovider, strip out the -2 from the admin and dev segment @@ -1092,9 +1093,6 @@ public function testURLSegmentAutoUpdateLocalized() i18n::set_locale($oldLocale); } - /** - * @covers \SilverStripe\CMS\Model\SiteTree::validURLSegment - */ public function testValidURLSegmentURLSegmentConflicts() { $sitetree = new SiteTree(); @@ -1124,9 +1122,6 @@ public function testValidURLSegmentURLSegmentConflicts() $this->assertTrue($sitetree->validURLSegment()); } - /** - * @covers \SilverStripe\CMS\Model\SiteTree::validURLSegment - */ public function testValidURLSegmentClassNameConflicts() { $sitetree = new SiteTree(); @@ -1135,9 +1130,6 @@ public function testValidURLSegmentClassNameConflicts() $this->assertTrue($sitetree->validURLSegment(), 'Class names are no longer conflicts'); } - /** - * @covers \SilverStripe\CMS\Model\SiteTree::validURLSegment - */ public function testValidURLSegmentControllerConflicts() { Config::modify()->set(SiteTree::class, 'nested_urls', true); @@ -1273,11 +1265,11 @@ public function testAllowedChildrenContainsCoreSubclassesButNotHiddenClass() /** * Tests that various types of SiteTree classes will or will not be returned from the allowedChildren method - * @dataProvider allowedChildrenProvider * @param string $className * @param array $expected * @param string $assertionMessage */ + #[DataProvider('allowedChildrenProvider')] public function testAllowedChildren($className, $expected, $assertionMessage) { $class = new $className; @@ -1287,7 +1279,7 @@ public function testAllowedChildren($className, $expected, $assertionMessage) /** * @return array */ - public function allowedChildrenProvider() + public static function allowedChildrenProvider() { return [ [ @@ -1525,7 +1517,7 @@ public function testMetaComponents() $charset = Config::inst()->get(ContentNegotiator::class, 'encoding'); $mockVersionProvider = $this->getMockBuilder(VersionProvider::class) - ->setMethods(['getModuleVersion']) + ->onlyMethods(['getModuleVersion']) ->getMock(); $mockVersionProvider->method('getModuleVersion')->willReturn('4.50.99'); $page->setVersionProvider($mockVersionProvider); @@ -1764,14 +1756,14 @@ public function testTreeTitleCache() $pageClass = array_values(SiteTree::page_type_classes())[0]; $mockPageMissesCache = $this->getMockBuilder($pageClass) - ->setMethods(['canCreate']) + ->onlyMethods(['canCreate']) ->getMock(); $mockPageMissesCache ->expects($this->exactly(3)) ->method('canCreate'); $mockPageHitsCache = $this->getMockBuilder($pageClass) - ->setMethods(['canCreate']) + ->onlyMethods(['canCreate']) ->getMock(); $mockPageHitsCache ->expects($this->never()) @@ -2092,9 +2084,7 @@ public function testCMSEditLink() ); } - /** - * @dataProvider provideSanitiseExtraMeta - */ + #[DataProvider('provideSanitiseExtraMeta')] public function testSanitiseExtraMeta(string $extraMeta, string $expected, string $message): void { $siteTree = new SiteTree(); @@ -2103,7 +2093,7 @@ public function testSanitiseExtraMeta(string $extraMeta, string $expected, strin $this->assertSame($expected, $siteTree->ExtraMeta, $message); } - public function provideSanitiseExtraMeta(): array + public static function provideSanitiseExtraMeta(): array { return [ [ diff --git a/tests/php/Search/ZZZSearchFormTest.php b/tests/php/Search/ZZZSearchFormTest.php index 35bed9a6e6..75f2769127 100644 --- a/tests/php/Search/ZZZSearchFormTest.php +++ b/tests/php/Search/ZZZSearchFormTest.php @@ -287,9 +287,6 @@ public function testPagesRestrictedToSpecificGroupNotIncluded() Security::setCurrentUser(null); } - /** - * - */ public function testInheritedRestrictedPagesNotIncluded() { $request = new HTTPRequest('GET', 'search', ['Search'=>'inheritRestrictedView']);