Skip to content

Commit

Permalink
Merge pull request #598 from creative-commoners/pulls/4/phpunit11
Browse files Browse the repository at this point in the history
DEP Use PHPUnit 11
  • Loading branch information
GuySartorelli authored Sep 18, 2024
2 parents 4eb8fea + 100ccc9 commit f58a863
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 25 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"silverstripe/versioned": "^3"
},
"require-dev": {
"phpunit/phpunit": "^9.6",
"phpunit/phpunit": "^11.3",
"squizlabs/php_codesniffer": "^3",
"silverstripe/standards": "^1",
"phpstan/extension-installer": "^1.3"
Expand Down
7 changes: 3 additions & 4 deletions tests/php/FileSubsitesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use SilverStripe\Subsites\Model\Subsite;
use SilverStripe\Security\Member;
use ReflectionMethod;
use PHPUnit\Framework\Attributes\DataProvider;

class FileSubsitesTest extends BaseSubsiteTest
{
Expand Down Expand Up @@ -74,9 +75,7 @@ public function testWritingSubsiteID()
$this->assertEquals($folder->SubsiteID, $file->SubsiteID);
}

/**
* @dataProvider provideTestCanEdit
*/
#[DataProvider('provideTestCanEdit')]
public function testCanEdit(
string $fileKey,
string $memberKey,
Expand All @@ -91,7 +90,7 @@ public function testCanEdit(
$this->assertSame($expected, $file->canEdit($member));
}

public function provideTestCanEdit(): array
public static function provideTestCanEdit(): array
{
$ret = [];
$data = [
Expand Down
7 changes: 3 additions & 4 deletions tests/php/Service/ThemeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use SilverStripe\Subsites\Model\Subsite;
use SilverStripe\Subsites\Service\ThemeResolver;
use SilverStripe\View\SSViewer;
use PHPUnit\Framework\Attributes\DataProvider;

class ThemeResolverTest extends SapphireTest
{
Expand Down Expand Up @@ -64,9 +65,7 @@ public function testSubsiteWithCustomThemeDoesNotCascadeUpTheList()
$this->assertSame($expected, $resolver->getThemeList($subsite));
}

/**
* @dataProvider customThemeDefinitionsAreRespectedProvider
*/
#[DataProvider('customThemeDefinitionsAreRespectedProvider')]
public function testCustomThemeDefinitionsAreRespected($themeOptions, $siteTheme, $expected)
{
Config::modify()->set(ThemeResolver::class, 'theme_options', $themeOptions);
Expand All @@ -79,7 +78,7 @@ public function testCustomThemeDefinitionsAreRespected($themeOptions, $siteTheme
$this->assertSame($expected, $resolver->getThemeList($subsite));
}

public function customThemeDefinitionsAreRespectedProvider()
public static function customThemeDefinitionsAreRespectedProvider()
{
return [
// Simple
Expand Down
15 changes: 7 additions & 8 deletions tests/php/SiteTreeSubsitesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use SilverStripe\Versioned\Versioned;
use SilverStripe\View\SSViewer;
use TractorCow\Fluent\Extension\FluentSiteTreeExtension;
use PHPUnit\Framework\Attributes\DataProvider;

class SiteTreeSubsitesTest extends BaseSubsiteTest
{
Expand Down Expand Up @@ -94,17 +95,15 @@ public function testBasicSanity()
$this->assertInstanceOf(FieldList::class, singleton(SubsitesVirtualPage::class)->getCMSFields());
}

public function errorPageLocationsProvider()
public static function errorPageLocationsProvider()
{
return [
['domaintest1', '/error-500-one.example.org.html'],
['domaintestVagrant', '/error-500-localhost8080.html']
];
}

/**
* @dataProvider errorPageLocationsProvider
*/
#[DataProvider('errorPageLocationsProvider')]
public function testErrorPageLocations($subsiteFixtureName, $expectedFilename)
{
$static_path = Config::inst()->get(ErrorPage::class, 'static_filepath');
Expand Down Expand Up @@ -382,8 +381,8 @@ public function testValidateURLSegment()
/**
* @param bool $withChildren
* @param int $expectedChildren
* @dataProvider duplicateToSubsiteProvider
*/
#[DataProvider('duplicateToSubsiteProvider')]
public function testDuplicateToSubsite($withChildren, $expectedChildren)
{
/** @var SiteTree $page */
Expand All @@ -408,7 +407,7 @@ public function testDuplicateToSubsite($withChildren, $expectedChildren)
/**
* @return array[]
*/
public function duplicateToSubsiteProvider()
public static function duplicateToSubsiteProvider()
{
return [
[true, 1],
Expand Down Expand Up @@ -437,7 +436,7 @@ public function testThemeResolverIsUsedForSettingThemeList()
SiteTree::singleton()->extend('contentcontrollerInit', $controller);
}

public function provideAlternateAbsoluteLink()
public static function provideAlternateAbsoluteLink()
{
return [
['home', null, 'http://localhost'],
Expand All @@ -452,11 +451,11 @@ public function provideAlternateAbsoluteLink()
}

/**
* @dataProvider provideAlternateAbsoluteLink
* @param string $pageFixtureName
* @param string|null $action
* @param string $expectedAbsoluteLink
*/
#[DataProvider('provideAlternateAbsoluteLink')]
public function testAlternateAbsoluteLink($pageFixtureName, $action, $expectedAbsoluteLink)
{
// Setting a control value, in case base url is set for the installation under test
Expand Down
5 changes: 3 additions & 2 deletions tests/php/SubsiteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use SilverStripe\Subsites\Model\SubsiteDomain;
use SilverStripe\Subsites\State\SubsiteState;
use UnexpectedValueException;
use PHPUnit\Framework\Attributes\DataProvider;

class SubsiteTest extends BaseSubsiteTest
{
Expand Down Expand Up @@ -317,8 +318,8 @@ public function testDefaultDomain()
* @param string $identifier Fixture identifier
* @param bool $currentIsSecure Whether the current base URL should be secure
* @param string $expected The expected base URL for the subsite or subsite domain
* @dataProvider domainProtocolProvider
*/
#[DataProvider('domainProtocolProvider')]
public function testDomainProtocol($class, $identifier, $currentIsSecure, $expected)
{
/** @var Subsite|SubsiteDomain $model */
Expand All @@ -328,7 +329,7 @@ public function testDomainProtocol($class, $identifier, $currentIsSecure, $expec
$this->assertSame($this->normaliseTrailingSlash($expected), $model->absoluteBaseURL());
}

public function domainProtocolProvider()
public static function domainProtocolProvider()
{
return [
[Subsite::class, 'domaintest2', false, 'http://two.mysite.com'],
Expand Down
13 changes: 7 additions & 6 deletions tests/php/WildcardDomainFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use SilverStripe\Dev\SapphireTest;
use SilverStripe\Subsites\Forms\WildcardDomainField;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* Tests {@see WildcardDomainField}
Expand All @@ -14,9 +15,9 @@ class WildcardDomainFieldTest extends SapphireTest
/**
* Check that valid domains are accepted
*
* @dataProvider validDomains
* @param $domain
*/
#[DataProvider('validDomains')]
public function testValidDomains($domain)
{
$field = new WildcardDomainField('DomainField');
Expand All @@ -26,9 +27,9 @@ public function testValidDomains($domain)
/**
* Check that valid domains are accepted
*
* @dataProvider invalidDomains
* @param $domain
*/
#[DataProvider('invalidDomains')]
public function testInvalidDomains($domain)
{
$field = new WildcardDomainField('DomainField');
Expand All @@ -38,16 +39,16 @@ public function testInvalidDomains($domain)
/**
* Check that valid domains are accepted
*
* @dataProvider validWildcards
* @param $domain
*/
#[DataProvider('validWildcards')]
public function testValidWildcards($domain)
{
$field = new WildcardDomainField('DomainField');
$this->assertTrue($field->checkHostname($domain), "Validate that {$domain} is a valid domain wildcard");
}

public function validDomains()
public static function validDomains()
{
return [
['www.mysite.com'],
Expand All @@ -60,7 +61,7 @@ public function validDomains()
];
}

public function invalidDomains()
public static function invalidDomains()
{
return [
['-mysite'],
Expand All @@ -77,7 +78,7 @@ public function invalidDomains()
];
}

public function validWildcards()
public static function validWildcards()
{
return [
['*.mysite.com'],
Expand Down

0 comments on commit f58a863

Please sign in to comment.