DEP Use PHPUnit 11

This commit is contained in:
Steve Boyd 2024-09-10 11:28:27 +12:00
parent 4eb8fea076
commit 100ccc98fb
6 changed files with 24 additions and 25 deletions

View File

@ -24,7 +24,7 @@
"silverstripe/versioned": "^3" "silverstripe/versioned": "^3"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^9.6", "phpunit/phpunit": "^11.3",
"squizlabs/php_codesniffer": "^3", "squizlabs/php_codesniffer": "^3",
"silverstripe/standards": "^1", "silverstripe/standards": "^1",
"phpstan/extension-installer": "^1.3" "phpstan/extension-installer": "^1.3"

View File

@ -10,6 +10,7 @@ use SilverStripe\Subsites\Extensions\FileSubsites;
use SilverStripe\Subsites\Model\Subsite; use SilverStripe\Subsites\Model\Subsite;
use SilverStripe\Security\Member; use SilverStripe\Security\Member;
use ReflectionMethod; use ReflectionMethod;
use PHPUnit\Framework\Attributes\DataProvider;
class FileSubsitesTest extends BaseSubsiteTest class FileSubsitesTest extends BaseSubsiteTest
{ {
@ -74,9 +75,7 @@ class FileSubsitesTest extends BaseSubsiteTest
$this->assertEquals($folder->SubsiteID, $file->SubsiteID); $this->assertEquals($folder->SubsiteID, $file->SubsiteID);
} }
/** #[DataProvider('provideTestCanEdit')]
* @dataProvider provideTestCanEdit
*/
public function testCanEdit( public function testCanEdit(
string $fileKey, string $fileKey,
string $memberKey, string $memberKey,
@ -91,7 +90,7 @@ class FileSubsitesTest extends BaseSubsiteTest
$this->assertSame($expected, $file->canEdit($member)); $this->assertSame($expected, $file->canEdit($member));
} }
public function provideTestCanEdit(): array public static function provideTestCanEdit(): array
{ {
$ret = []; $ret = [];
$data = [ $data = [

View File

@ -7,6 +7,7 @@ use SilverStripe\Dev\SapphireTest;
use SilverStripe\Subsites\Model\Subsite; use SilverStripe\Subsites\Model\Subsite;
use SilverStripe\Subsites\Service\ThemeResolver; use SilverStripe\Subsites\Service\ThemeResolver;
use SilverStripe\View\SSViewer; use SilverStripe\View\SSViewer;
use PHPUnit\Framework\Attributes\DataProvider;
class ThemeResolverTest extends SapphireTest class ThemeResolverTest extends SapphireTest
{ {
@ -64,9 +65,7 @@ class ThemeResolverTest extends SapphireTest
$this->assertSame($expected, $resolver->getThemeList($subsite)); $this->assertSame($expected, $resolver->getThemeList($subsite));
} }
/** #[DataProvider('customThemeDefinitionsAreRespectedProvider')]
* @dataProvider customThemeDefinitionsAreRespectedProvider
*/
public function testCustomThemeDefinitionsAreRespected($themeOptions, $siteTheme, $expected) public function testCustomThemeDefinitionsAreRespected($themeOptions, $siteTheme, $expected)
{ {
Config::modify()->set(ThemeResolver::class, 'theme_options', $themeOptions); Config::modify()->set(ThemeResolver::class, 'theme_options', $themeOptions);
@ -79,7 +78,7 @@ class ThemeResolverTest extends SapphireTest
$this->assertSame($expected, $resolver->getThemeList($subsite)); $this->assertSame($expected, $resolver->getThemeList($subsite));
} }
public function customThemeDefinitionsAreRespectedProvider() public static function customThemeDefinitionsAreRespectedProvider()
{ {
return [ return [
// Simple // Simple

View File

@ -26,6 +26,7 @@ use SilverStripe\Subsites\Tests\SiteTreeSubsitesTest\TestErrorPage;
use SilverStripe\Versioned\Versioned; use SilverStripe\Versioned\Versioned;
use SilverStripe\View\SSViewer; use SilverStripe\View\SSViewer;
use TractorCow\Fluent\Extension\FluentSiteTreeExtension; use TractorCow\Fluent\Extension\FluentSiteTreeExtension;
use PHPUnit\Framework\Attributes\DataProvider;
class SiteTreeSubsitesTest extends BaseSubsiteTest class SiteTreeSubsitesTest extends BaseSubsiteTest
{ {
@ -94,7 +95,7 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
$this->assertInstanceOf(FieldList::class, singleton(SubsitesVirtualPage::class)->getCMSFields()); $this->assertInstanceOf(FieldList::class, singleton(SubsitesVirtualPage::class)->getCMSFields());
} }
public function errorPageLocationsProvider() public static function errorPageLocationsProvider()
{ {
return [ return [
['domaintest1', '/error-500-one.example.org.html'], ['domaintest1', '/error-500-one.example.org.html'],
@ -102,9 +103,7 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
]; ];
} }
/** #[DataProvider('errorPageLocationsProvider')]
* @dataProvider errorPageLocationsProvider
*/
public function testErrorPageLocations($subsiteFixtureName, $expectedFilename) public function testErrorPageLocations($subsiteFixtureName, $expectedFilename)
{ {
$static_path = Config::inst()->get(ErrorPage::class, 'static_filepath'); $static_path = Config::inst()->get(ErrorPage::class, 'static_filepath');
@ -382,8 +381,8 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
/** /**
* @param bool $withChildren * @param bool $withChildren
* @param int $expectedChildren * @param int $expectedChildren
* @dataProvider duplicateToSubsiteProvider
*/ */
#[DataProvider('duplicateToSubsiteProvider')]
public function testDuplicateToSubsite($withChildren, $expectedChildren) public function testDuplicateToSubsite($withChildren, $expectedChildren)
{ {
/** @var SiteTree $page */ /** @var SiteTree $page */
@ -408,7 +407,7 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
/** /**
* @return array[] * @return array[]
*/ */
public function duplicateToSubsiteProvider() public static function duplicateToSubsiteProvider()
{ {
return [ return [
[true, 1], [true, 1],
@ -437,7 +436,7 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
SiteTree::singleton()->extend('contentcontrollerInit', $controller); SiteTree::singleton()->extend('contentcontrollerInit', $controller);
} }
public function provideAlternateAbsoluteLink() public static function provideAlternateAbsoluteLink()
{ {
return [ return [
['home', null, 'http://localhost'], ['home', null, 'http://localhost'],
@ -452,11 +451,11 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
} }
/** /**
* @dataProvider provideAlternateAbsoluteLink
* @param string $pageFixtureName * @param string $pageFixtureName
* @param string|null $action * @param string|null $action
* @param string $expectedAbsoluteLink * @param string $expectedAbsoluteLink
*/ */
#[DataProvider('provideAlternateAbsoluteLink')]
public function testAlternateAbsoluteLink($pageFixtureName, $action, $expectedAbsoluteLink) public function testAlternateAbsoluteLink($pageFixtureName, $action, $expectedAbsoluteLink)
{ {
// Setting a control value, in case base url is set for the installation under test // Setting a control value, in case base url is set for the installation under test

View File

@ -13,6 +13,7 @@ use SilverStripe\Subsites\Model\Subsite;
use SilverStripe\Subsites\Model\SubsiteDomain; use SilverStripe\Subsites\Model\SubsiteDomain;
use SilverStripe\Subsites\State\SubsiteState; use SilverStripe\Subsites\State\SubsiteState;
use UnexpectedValueException; use UnexpectedValueException;
use PHPUnit\Framework\Attributes\DataProvider;
class SubsiteTest extends BaseSubsiteTest class SubsiteTest extends BaseSubsiteTest
{ {
@ -317,8 +318,8 @@ class SubsiteTest extends BaseSubsiteTest
* @param string $identifier Fixture identifier * @param string $identifier Fixture identifier
* @param bool $currentIsSecure Whether the current base URL should be secure * @param bool $currentIsSecure Whether the current base URL should be secure
* @param string $expected The expected base URL for the subsite or subsite domain * @param string $expected The expected base URL for the subsite or subsite domain
* @dataProvider domainProtocolProvider
*/ */
#[DataProvider('domainProtocolProvider')]
public function testDomainProtocol($class, $identifier, $currentIsSecure, $expected) public function testDomainProtocol($class, $identifier, $currentIsSecure, $expected)
{ {
/** @var Subsite|SubsiteDomain $model */ /** @var Subsite|SubsiteDomain $model */
@ -328,7 +329,7 @@ class SubsiteTest extends BaseSubsiteTest
$this->assertSame($this->normaliseTrailingSlash($expected), $model->absoluteBaseURL()); $this->assertSame($this->normaliseTrailingSlash($expected), $model->absoluteBaseURL());
} }
public function domainProtocolProvider() public static function domainProtocolProvider()
{ {
return [ return [
[Subsite::class, 'domaintest2', false, 'http://two.mysite.com'], [Subsite::class, 'domaintest2', false, 'http://two.mysite.com'],

View File

@ -4,6 +4,7 @@ namespace SilverStripe\Subsites\Tests;
use SilverStripe\Dev\SapphireTest; use SilverStripe\Dev\SapphireTest;
use SilverStripe\Subsites\Forms\WildcardDomainField; use SilverStripe\Subsites\Forms\WildcardDomainField;
use PHPUnit\Framework\Attributes\DataProvider;
/** /**
* Tests {@see WildcardDomainField} * Tests {@see WildcardDomainField}
@ -14,9 +15,9 @@ class WildcardDomainFieldTest extends SapphireTest
/** /**
* Check that valid domains are accepted * Check that valid domains are accepted
* *
* @dataProvider validDomains
* @param $domain * @param $domain
*/ */
#[DataProvider('validDomains')]
public function testValidDomains($domain) public function testValidDomains($domain)
{ {
$field = new WildcardDomainField('DomainField'); $field = new WildcardDomainField('DomainField');
@ -26,9 +27,9 @@ class WildcardDomainFieldTest extends SapphireTest
/** /**
* Check that valid domains are accepted * Check that valid domains are accepted
* *
* @dataProvider invalidDomains
* @param $domain * @param $domain
*/ */
#[DataProvider('invalidDomains')]
public function testInvalidDomains($domain) public function testInvalidDomains($domain)
{ {
$field = new WildcardDomainField('DomainField'); $field = new WildcardDomainField('DomainField');
@ -38,16 +39,16 @@ class WildcardDomainFieldTest extends SapphireTest
/** /**
* Check that valid domains are accepted * Check that valid domains are accepted
* *
* @dataProvider validWildcards
* @param $domain * @param $domain
*/ */
#[DataProvider('validWildcards')]
public function testValidWildcards($domain) public function testValidWildcards($domain)
{ {
$field = new WildcardDomainField('DomainField'); $field = new WildcardDomainField('DomainField');
$this->assertTrue($field->checkHostname($domain), "Validate that {$domain} is a valid domain wildcard"); $this->assertTrue($field->checkHostname($domain), "Validate that {$domain} is a valid domain wildcard");
} }
public function validDomains() public static function validDomains()
{ {
return [ return [
['www.mysite.com'], ['www.mysite.com'],
@ -60,7 +61,7 @@ class WildcardDomainFieldTest extends SapphireTest
]; ];
} }
public function invalidDomains() public static function invalidDomains()
{ {
return [ return [
['-mysite'], ['-mysite'],
@ -77,7 +78,7 @@ class WildcardDomainFieldTest extends SapphireTest
]; ];
} }
public function validWildcards() public static function validWildcards()
{ {
return [ return [
['*.mysite.com'], ['*.mysite.com'],