DEP Use PHPUnit 11

This commit is contained in:
Steve Boyd 2024-09-10 18:01:31 +12:00
parent ae89276432
commit 36686f7a26
10 changed files with 28 additions and 47 deletions

View File

@ -30,7 +30,7 @@
"silverstripe/vendor-plugin": "^2" "silverstripe/vendor-plugin": "^2"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^9.6", "phpunit/phpunit": "^11.3",
"squizlabs/php_codesniffer": "^3.7", "squizlabs/php_codesniffer": "^3.7",
"silverstripe/standards": "^1", "silverstripe/standards": "^1",
"phpstan/extension-installer": "^1.3" "phpstan/extension-installer": "^1.3"

View File

@ -619,14 +619,14 @@ class CMSMainTest extends FunctionalTest
Security::setCurrentUser($user); Security::setCurrentUser($user);
$pageClass = array_values(SiteTree::page_type_classes())[0]; $pageClass = array_values(SiteTree::page_type_classes())[0];
$mockPageMissesCache = $this->getMockBuilder($pageClass) $mockPageMissesCache = $this->getMockBuilder($pageClass)
->setMethods(['canCreate']) ->onlyMethods(['canCreate'])
->getMock(); ->getMock();
$mockPageMissesCache $mockPageMissesCache
->expects($this->exactly(3)) ->expects($this->exactly(3))
->method('canCreate'); ->method('canCreate');
$mockPageHitsCache = $this->getMockBuilder($pageClass) $mockPageHitsCache = $this->getMockBuilder($pageClass)
->setMethods(['canCreate']) ->onlyMethods(['canCreate'])
->getMock(); ->getMock();
$mockPageHitsCache $mockPageHitsCache
->expects($this->never()) ->expects($this->never())

View File

@ -157,7 +157,6 @@ class ContentControllerTest extends FunctionalTest
/** /**
* Tests that {@link ContentController::getViewer()} chooses the correct templates. * Tests that {@link ContentController::getViewer()} chooses the correct templates.
* *
* @covers \SilverStripe\CMS\Controllers\ContentController::getViewer()
**/ **/
public function testGetViewer() public function testGetViewer()
{ {

View File

@ -207,7 +207,6 @@ class ModelAsControllerTest extends FunctionalTest
/** /**
* *
* NOTE: This test requires nested_urls * NOTE: This test requires nested_urls
*
*/ */
public function testRedirectsNestedRenamedPagesWithGetParameters() public function testRedirectsNestedRenamedPagesWithGetParameters()
{ {
@ -225,7 +224,6 @@ class ModelAsControllerTest extends FunctionalTest
/** /**
* *
* NOTE: This test requires nested_urls * NOTE: This test requires nested_urls
*
*/ */
public function testDoesntRedirectToNestedRenamedPageWhenNewExists() public function testDoesntRedirectToNestedRenamedPageWhenNewExists()
{ {
@ -255,7 +253,6 @@ class ModelAsControllerTest extends FunctionalTest
/** /**
* *
* NOTE: This test requires nested_urls * NOTE: This test requires nested_urls
*
*/ */
public function testFindOldPage() public function testFindOldPage()
{ {

View File

@ -5,7 +5,7 @@ namespace SilverStripe\CMS\Tests\Controllers;
use SilverStripe\CMS\Controllers\ContentController; use SilverStripe\CMS\Controllers\ContentController;
use SilverStripe\Dev\TestOnly; use SilverStripe\Dev\TestOnly;
class SiteTreeTest_NamespaceMapTestController extends ContentController implements TestOnly class SiteTreeTest_NamespaceMapTestNodeController extends ContentController implements TestOnly
{ {
} }

View File

@ -11,6 +11,7 @@ use SilverStripe\Assets\Dev\TestAssetStore;
use SilverStripe\Control\Controller; use SilverStripe\Control\Controller;
use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\FunctionalTest; use SilverStripe\Dev\FunctionalTest;
use PHPUnit\Framework\Attributes\DataProvider;
class RedirectorPageTest extends FunctionalTest class RedirectorPageTest extends FunctionalTest
{ {
@ -61,7 +62,7 @@ class RedirectorPageTest extends FunctionalTest
); );
} }
public function provideEmptyRedirectors() public static function provideEmptyRedirectors()
{ {
return [ return [
'use 200' => [ 'use 200' => [
@ -73,9 +74,7 @@ class RedirectorPageTest extends FunctionalTest
]; ];
} }
/** #[DataProvider('provideEmptyRedirectors')]
* @dataProvider provideEmptyRedirectors
*/
public function testEmptyRedirectors(bool $use404) public function testEmptyRedirectors(bool $use404)
{ {
Config::modify()->set(RedirectorPageController::class, 'missing_redirect_is_404', $use404); Config::modify()->set(RedirectorPageController::class, 'missing_redirect_is_404', $use404);
@ -181,7 +180,7 @@ class RedirectorPageTest extends FunctionalTest
$this->assertStringContainsString("FileTest.txt", $page->Link()); $this->assertStringContainsString("FileTest.txt", $page->Link());
} }
public function provideUnpublishedTarget() public static function provideUnpublishedTarget()
{ {
return [ return [
'use 200 with sitetree' => [ 'use 200 with sitetree' => [
@ -203,9 +202,7 @@ class RedirectorPageTest extends FunctionalTest
]; ];
} }
/** #[DataProvider('provideUnpublishedTarget')]
* @dataProvider provideUnpublishedTarget
*/
public function testUnpublishedTarget(bool $use404, bool $isFile) public function testUnpublishedTarget(bool $use404, bool $isFile)
{ {
Config::modify()->set(RedirectorPageController::class, 'missing_redirect_is_404', $use404); Config::modify()->set(RedirectorPageController::class, 'missing_redirect_is_404', $use404);

View File

@ -11,6 +11,7 @@ use SilverStripe\Security\Security;
use SilverStripe\SiteConfig\SiteConfig; use SilverStripe\SiteConfig\SiteConfig;
use SilverStripe\Subsites\Extensions\SiteTreeSubsites; use SilverStripe\Subsites\Extensions\SiteTreeSubsites;
use SilverStripe\Versioned\Versioned; use SilverStripe\Versioned\Versioned;
use PHPUnit\Framework\Attributes\DataProvider;
class SiteTreePermissionsTest extends FunctionalTest class SiteTreePermissionsTest extends FunctionalTest
{ {
@ -524,8 +525,8 @@ class SiteTreePermissionsTest extends FunctionalTest
/** /**
* Test permissions on duplicate page * Test permissions on duplicate page
* @dataProvider groupWithPermissions
*/ */
#[DataProvider('groupWithPermissions')]
public function testDuplicatePageWithGroupPermissions(string $userName, string $method, bool $expected) public function testDuplicatePageWithGroupPermissions(string $userName, string $method, bool $expected)
{ {
$originalPage = $this->objFromFixture(SiteTree::class, 'originalpage'); $originalPage = $this->objFromFixture(SiteTree::class, 'originalpage');
@ -538,7 +539,7 @@ class SiteTreePermissionsTest extends FunctionalTest
$this->assertSame($dupe->{$method}($user), $expected); $this->assertSame($dupe->{$method}($user), $expected);
} }
public function groupWithPermissions(): array public static function groupWithPermissions(): array
{ {
return [ return [
'Subadmin can view page duplicate.' => [ 'Subadmin can view page duplicate.' => [

View File

@ -8,11 +8,11 @@ use ReflectionMethod;
use SilverStripe\CMS\Model\RedirectorPage; use SilverStripe\CMS\Model\RedirectorPage;
use SilverStripe\CMS\Model\SiteTree; use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\CMS\Model\VirtualPage; use SilverStripe\CMS\Model\VirtualPage;
use SilverStripe\CMS\Tests\Controllers\SiteTreeTest_NamespaceMapTestController; use SilverStripe\CMS\Tests\Controllers\SiteTreeTest_NamespaceMapTestNodeController;
use SilverStripe\CMS\Tests\CMSEditLinkExtensionTest\BelongsToPage; use SilverStripe\CMS\Tests\CMSEditLinkExtensionTest\BelongsToPage;
use SilverStripe\CMS\Tests\CMSEditLinkExtensionTest\PageWithChild; use SilverStripe\CMS\Tests\CMSEditLinkExtensionTest\PageWithChild;
use SilverStripe\CMS\Tests\Model\SiteTreeBrokenLinksTest\NotPageObject; use SilverStripe\CMS\Tests\Model\SiteTreeBrokenLinksTest\NotPageObject;
use SilverStripe\CMS\Tests\Page\SiteTreeTest_NamespaceMapTest; use SilverStripe\CMS\Tests\Page\SiteTreeTest_NamespaceMapTestNode;
use SilverStripe\Control\ContentNegotiator; use SilverStripe\Control\ContentNegotiator;
use SilverStripe\Control\Controller; use SilverStripe\Control\Controller;
use SilverStripe\Control\Director; use SilverStripe\Control\Director;
@ -42,6 +42,7 @@ use Page;
use PageController; use PageController;
use const RESOURCES_DIR; use const RESOURCES_DIR;
use PHPUnit\Framework\Attributes\DataProvider;
class SiteTreeTest extends SapphireTest class SiteTreeTest extends SapphireTest
{ {
@ -71,7 +72,7 @@ class SiteTreeTest extends SapphireTest
NotPageObject::class, NotPageObject::class,
]; ];
public function reservedSegmentsProvider() public static function reservedSegmentsProvider()
{ {
return [ return [
// segments reserved by rules // segments reserved by rules
@ -142,8 +143,8 @@ class SiteTreeTest extends SapphireTest
/** /**
* Check if reserved URL's are properly appended with a number at top level * Check if reserved URL's are properly appended with a number at top level
* @dataProvider reservedSegmentsProvider
*/ */
#[DataProvider('reservedSegmentsProvider')]
public function testDisallowedURLGeneration($title, $urlSegment) public function testDisallowedURLGeneration($title, $urlSegment)
{ {
$page = new SiteTree(['Title' => $title]); $page = new SiteTree(['Title' => $title]);
@ -155,8 +156,8 @@ class SiteTreeTest extends SapphireTest
/** /**
* Check if reserved URL's are not appended with a number on a child page * 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 * 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) public function testDisallowedChildURLGeneration($title, $urlSegment)
{ {
// Using the same dataprovider, strip out the -2 from the admin and dev segment // Using the same dataprovider, strip out the -2 from the admin and dev segment
@ -1092,9 +1093,6 @@ class SiteTreeTest extends SapphireTest
i18n::set_locale($oldLocale); i18n::set_locale($oldLocale);
} }
/**
* @covers \SilverStripe\CMS\Model\SiteTree::validURLSegment
*/
public function testValidURLSegmentURLSegmentConflicts() public function testValidURLSegmentURLSegmentConflicts()
{ {
$sitetree = new SiteTree(); $sitetree = new SiteTree();
@ -1124,9 +1122,6 @@ class SiteTreeTest extends SapphireTest
$this->assertTrue($sitetree->validURLSegment()); $this->assertTrue($sitetree->validURLSegment());
} }
/**
* @covers \SilverStripe\CMS\Model\SiteTree::validURLSegment
*/
public function testValidURLSegmentClassNameConflicts() public function testValidURLSegmentClassNameConflicts()
{ {
$sitetree = new SiteTree(); $sitetree = new SiteTree();
@ -1135,9 +1130,6 @@ class SiteTreeTest extends SapphireTest
$this->assertTrue($sitetree->validURLSegment(), 'Class names are no longer conflicts'); $this->assertTrue($sitetree->validURLSegment(), 'Class names are no longer conflicts');
} }
/**
* @covers \SilverStripe\CMS\Model\SiteTree::validURLSegment
*/
public function testValidURLSegmentControllerConflicts() public function testValidURLSegmentControllerConflicts()
{ {
Config::modify()->set(SiteTree::class, 'nested_urls', true); Config::modify()->set(SiteTree::class, 'nested_urls', true);
@ -1273,11 +1265,11 @@ class SiteTreeTest extends SapphireTest
/** /**
* Tests that various types of SiteTree classes will or will not be returned from the allowedChildren method * Tests that various types of SiteTree classes will or will not be returned from the allowedChildren method
* @dataProvider allowedChildrenProvider
* @param string $className * @param string $className
* @param array $expected * @param array $expected
* @param string $assertionMessage * @param string $assertionMessage
*/ */
#[DataProvider('allowedChildrenProvider')]
public function testAllowedChildren($className, $expected, $assertionMessage) public function testAllowedChildren($className, $expected, $assertionMessage)
{ {
$class = new $className; $class = new $className;
@ -1287,7 +1279,7 @@ class SiteTreeTest extends SapphireTest
/** /**
* @return array * @return array
*/ */
public function allowedChildrenProvider() public static function allowedChildrenProvider()
{ {
return [ return [
[ [
@ -1525,7 +1517,7 @@ class SiteTreeTest extends SapphireTest
$charset = Config::inst()->get(ContentNegotiator::class, 'encoding'); $charset = Config::inst()->get(ContentNegotiator::class, 'encoding');
$mockVersionProvider = $this->getMockBuilder(VersionProvider::class) $mockVersionProvider = $this->getMockBuilder(VersionProvider::class)
->setMethods(['getModuleVersion']) ->onlyMethods(['getModuleVersion'])
->getMock(); ->getMock();
$mockVersionProvider->method('getModuleVersion')->willReturn('4.50.99'); $mockVersionProvider->method('getModuleVersion')->willReturn('4.50.99');
$page->setVersionProvider($mockVersionProvider); $page->setVersionProvider($mockVersionProvider);
@ -1752,8 +1744,8 @@ class SiteTreeTest extends SapphireTest
'SilverStripe\\CMS\\Tests\\Page' => 'SilverStripe\\CMS\\Tests\\Controllers', 'SilverStripe\\CMS\\Tests\\Page' => 'SilverStripe\\CMS\\Tests\\Controllers',
]); ]);
$namespacedSiteTree = new SiteTreeTest_NamespaceMapTest(); $namespacedSiteTree = new SiteTreeTest_NamespaceMapTestNode();
$this->assertSame(SiteTreeTest_NamespaceMapTestController::class, $namespacedSiteTree->getControllerName()); $this->assertSame(SiteTreeTest_NamespaceMapTestNodeController::class, $namespacedSiteTree->getControllerName());
} }
public function testTreeTitleCache() public function testTreeTitleCache()
@ -1764,14 +1756,14 @@ class SiteTreeTest extends SapphireTest
$pageClass = array_values(SiteTree::page_type_classes())[0]; $pageClass = array_values(SiteTree::page_type_classes())[0];
$mockPageMissesCache = $this->getMockBuilder($pageClass) $mockPageMissesCache = $this->getMockBuilder($pageClass)
->setMethods(['canCreate']) ->onlyMethods(['canCreate'])
->getMock(); ->getMock();
$mockPageMissesCache $mockPageMissesCache
->expects($this->exactly(3)) ->expects($this->exactly(3))
->method('canCreate'); ->method('canCreate');
$mockPageHitsCache = $this->getMockBuilder($pageClass) $mockPageHitsCache = $this->getMockBuilder($pageClass)
->setMethods(['canCreate']) ->onlyMethods(['canCreate'])
->getMock(); ->getMock();
$mockPageHitsCache $mockPageHitsCache
->expects($this->never()) ->expects($this->never())
@ -2092,9 +2084,7 @@ class SiteTreeTest extends SapphireTest
); );
} }
/** #[DataProvider('provideSanitiseExtraMeta')]
* @dataProvider provideSanitiseExtraMeta
*/
public function testSanitiseExtraMeta(string $extraMeta, string $expected, string $message): void public function testSanitiseExtraMeta(string $extraMeta, string $expected, string $message): void
{ {
$siteTree = new SiteTree(); $siteTree = new SiteTree();
@ -2103,7 +2093,7 @@ class SiteTreeTest extends SapphireTest
$this->assertSame($expected, $siteTree->ExtraMeta, $message); $this->assertSame($expected, $siteTree->ExtraMeta, $message);
} }
public function provideSanitiseExtraMeta(): array public static function provideSanitiseExtraMeta(): array
{ {
return [ return [
[ [

View File

@ -5,7 +5,7 @@ namespace SilverStripe\CMS\Tests\Page;
use SilverStripe\CMS\Model\SiteTree; use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Dev\TestOnly; use SilverStripe\Dev\TestOnly;
class SiteTreeTest_NamespaceMapTest extends SiteTree implements TestOnly class SiteTreeTest_NamespaceMapTestNode extends SiteTree implements TestOnly
{ {
private static $table_name = 'SiteTreeTest_NamespaceMapTestNode'; private static $table_name = 'SiteTreeTest_NamespaceMapTestNode';
} }

View File

@ -287,9 +287,6 @@ class ZZZSearchFormTest extends FunctionalTest
Security::setCurrentUser(null); Security::setCurrentUser(null);
} }
/**
*
*/
public function testInheritedRestrictedPagesNotIncluded() public function testInheritedRestrictedPagesNotIncluded()
{ {
$request = new HTTPRequest('GET', 'search', ['Search'=>'inheritRestrictedView']); $request = new HTTPRequest('GET', 'search', ['Search'=>'inheritRestrictedView']);